Select [ResInvoiceT].[DBId], [ResInvoiceT].[Number], [ResInvoiceT].[Id], [ResInvoiceT].[Type], [ResGLMovement].*, [ResInvoiceT].[Total] from (Select [GLMovement].[DBId], [GLMovement].[GLPeriodId], [GLMovement].[EntryNumber], [GLMovement].[InvoiceTId], Sum(Round(Case When [CD] = ‘D’ Then [Amount] Else -[Amount] End, 2)) as [Total] from [GLMovement] INNER JOIN [GLAccount] ON ([GLMovement].[GLAccountId] = [GLAccount].[Id] and [GLMovement].[DBId] = [GLAccount].[DBId] and [GLAccount].[Type] = 11) where [GLMovement].[Type] = 1 Group by [GLMovement].[DBId], [GLMovement].[GLPeriodId], [GLMovement].[EntryNumber], [GLMovement].[InvoiceTId]) as [ResGLMovement] INNER JOIN (Select [DBId], [Id], [Number], [Type], Case When [Type] in (2, 4, 8, 9) Then -Round([InvoiceT].[BilledNoVAT] + [InvoiceT].[VAT], 2) Else Round([InvoiceT].[BilledNoVAT] + [InvoiceT].[VAT], 2) End as [Total] from [InvoiceT]) as [ResInvoiceT] ON ([ResGLMovement].[InvoiceTId] = [ResInvoiceT].[Id] and [ResGLMovement].[DBId] = [ResInvoiceT].[DBId]) where Not [ResGLMovement].[Total] = [ResInvoiceT].[Total] order by [ResInvoiceT].[DBId]