Thanks Gordon,
In order to avoid duplicates due to Credit Notes with multiple lines, it would be necessary to include a SELECT DISTINCT in the subqueries and then SUM both subqueries. Something like this:
SELECT T.[TYPE], T.[CR No],T.[Inv No], T.[Total]
FROM
(
SELECT
[TYPE], [CR No], [Inv No], SUM([Total]) as Total
FROM (
SELECT DISTINCT 'CR Memo' as [TYPE], T0.DocNum as [CR No], T1.BaseRef as [Inv No],-T0.DocTotal as [Total]
FROM
[dbo].[ORIN] T0 INNER JOIN
[dbo].[RIN1] T1 ON T0.DocEntry = T1.DocEntry AND T1.BaseType = '13')
GROUP BY [TYPE],[CR No],[Inv No]
UNION
SELECT
[TYPE], [CR No], [Inv No], SUM([Total]) as Total
FROM (
SELECT DISTINCT
'Invoice' as [TYPE], T3.DocNum as [CR No], T1.DocNum as [Inv No], T1.DocTotal as [Total]
FROM
[dbo].[INV1] T0 INNER JOIN
[dbo].[OINV] T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
[dbo].[RIN1] T2 ON T2.DocEntry = T0.TrgetEntry INNER JOIN
[dbo].[ORIN] T3 ON T3.DocEntry = T2.DocEntry
WHERE T0.TargetType='14')
GROUP BY [TYPE],[CR No],[Inv No]
) T
ORDER BY T.[CR No]
Kind Regards
Julian