Nos dois script abaixo, deverá ser informado o código da empresa. Substituir a tag Script 1 - Obtendo o número da nota fiscal de saída que apresentam diferenças create table #temp1 (autoid int, numero int, valor decimal(14,2)) insert into #temp1 select NfsEF.AutoID, NfsEF.Numero, SUM(TributacaoNFS.ValorImposto) from TributacaoNFS inner join NfsEF on NfsEF.AutoID = TributacaoNFS.NFSTributada where NfsEF.SituacaoNota = 'E' and NfsEF.FiltroEmpresa = (select Empresa.AutoId from Empresa where Empresa.Codigo = '') and TributacaoNFS.ImpostoTributado = 1 group by NfsEF.AutoID, NfsEF.Numero create table #temp2 (autoid int, numero int, valor decimal(14,2)) insert into #temp2 select NfsEF.AutoID, NfsEF.Numero, SUM(ItemNFSProdutoEF.ValorICMS) from ItemNFSProdutoEF inner join NfsEF on NfsEF.AutoID = ItemNFSProdutoEF.NFSItem where NfsEF.SituacaoNota = 'E' and NfsEF.FiltroEmpresa = (select Empresa.AutoId from Empresa where Empresa.Codigo = '') group by NfsEF.AutoID, NfsEF.Numero select #temp1.numero from #temp1 inner join #temp2 on #temp1.autoid = #temp2.autoid where #temp1.valor <> #temp2.valor Script 2 - Obtendo o número da nota fiscal de entrada que apresentam diferenças create table #temp3 (autoid int, numero int, valor decimal(14,2)) insert into #temp3 select NfeEF.AutoID, NfeEF.Numero, SUM(TributacaoNFE.ValorImposto) from TributacaoNFE inner join NfeEF on NfeEF.AutoID = TributacaoNFE.NFETributada where NfeEF.SituacaoNota = 'E' and NfeEF.FiltroEmpresa = (select Empresa.AutoId from Empresa where Empresa.Codigo = '') and TributacaoNFE.ImpostoTributado = 1 group by NfeEF.AutoID, NfeEF.Numero create table #temp4 (autoid int, numero int, valor decimal(14,2)) insert into #temp4 select NfeEF.AutoID, NfeEF.Numero, SUM(ItemNFEProdutoEF.ValorICMS) from ItemNFEProdutoEF inner join NfeEF on NfeEF.AutoID = ItemNFEProdutoEF.NFEItem where NfeEF.SituacaoNota = 'E' and NfeEF.FiltroEmpresa = (select Empresa.AutoId from Empresa where Empresa.Codigo = '') group by NfeEF.AutoID, NfeEF.Numero select #temp3.numero from #temp3 inner join #temp4 on #temp3.autoid = #temp4.autoid where #temp3.valor <> #temp4.valor