Para criar um lançamento de controle administrativo em lote deve ser utilizado o script abaixo, alterando os dados do titulo.
INSERT INTO dbo.t0515 (f0001idempresa, f0515idlancamentocusto, f0043idtransacao, f0517idperiodocusto, f0515datalancamento, f0515dataconciliacao, f0515usuarioconciliacao, f0515historico, f0515valor, f0043idtransacaorecuperacao, f0032ideventocontabilrecuperacao, f0515valorarecuperar, f0061idportadorrecuperacao, f0059idserierecuperacao, f0515datavencimento, f0002idestabrecuperacao) select t0060.f0001idempresa, row_number() over (order by f0060iddocumento) + (select max(t0515.f0515idlancamentocusto) from t0515), t0060.f0043idtransacao, (select f0517idperiodocusto from t0517 where dbo.fnCbaData(t0060.f0060dtavencto) between dbo.fnCbaData(t0517.f0517datainicio) and dbo.fnCbaData(t0517.f0517datafim)), t0060.f0060dtavencto, t0060.f0060dtavencto, (select t0004.f0004nome from t0004 where t0004.f0004idusuario = (select t0043.f0004idusuario from t0043 where t0043.f0043idtransacao = t0060.f0043idtransacao)), isnull((select top 1 t0153.f0153descricao from t0041 inner join t0153 on t0153.f0001idempresa = t0041.f0001idempresa and t0153.f0153iddescricao = t0041.f0153iddescricao where t0041.f0043idtransacao = t0060.f0043idtransacao), 'TIT PAGAR -' + t0060.f0060iddocumento + '-' + t0060.f0059idserie + '-' + convert(varchar, t0060.f0060idparcela)), t0060.f0060valordocumento, null, null, null, null, null, null, null from t0060 where f0060iddocumento = '31193/01' and f0059idserie ='TM' and f0050idclifor =106122 and f0060idparcela =1 and not exists(select top 1 1 from t0515 where t0515.f0043idtransacao = t0060.f0043idtransacao) -- Inserção do Detalhe do Controle Administrativo INSERT INTO dbo.t0516 (f0001idempresa, f0515idlancamentocusto, f0516iddetalhamento, f0513idplanocusto, f0514idconsumidor, f0516valor, f0516historico, f0622idunidadeconsumidora, f0516quantidade, f0516valorarecuperar, f0516quantidadearecuperar) select t0060.f0001idempresa, (select top 1 t0515.f0515idlancamentocusto from t0515 where t0515.f0043idtransacao = t0060.f0043idtransacao), 1, -- detalhamento 2264, -- conta do controle null, -- consumidor t0060.f0060valordocumento, null, --histórico 1, -- Unidade consumidora 1.000, -- Quantidade null, -- Valor Recuperar null -- Quantidade Recuperar from t0060 where f0060iddocumento = '31193/01' and f0059idserie ='TM' and f0050idclifor =106122 and f0060idparcela =1 and not exists(select top 1 1 from t0516 inner join t0515 on t0515.f0515idlancamentocusto = t0516.f0515idlancamentocusto where t0515.f0043idtransacao = t0060.f0043idtransacao)