Que tal buen día resulta que tengo dos querys diferentes pero con los mismos campos solo son diferentes tablas y necesito unirlos y que me realice la resta y me aparezca en el resultado hasta el momento ya los uni con UNION sin problema pero no encuentro como realizar la resta de los valores
1°
SELECT T3.[ItemCode], T3.[Dscription], T2.[CardCode], T2.[CardName], Cantidad=sum(T3.[Quantity]), T3.[unitMsr], Total=sum(T3.[TotalSumSy]) FROM [dbo].[OINV] T2 INNER JOIN [dbo].[INV1] T3 ON T2.DocEntry = T3.DocEntry WHERE T2.[DocType]<>'S' and T2.[DocDate] >= '[%0]' and T2.[DocDate] <= '[%1]' GROUP BY T3.[ItemCode], T3.[Dscription], T2.[CardCode], T2.[CardName], T3.[Quantity], T3.[unitMsr], T3.[TotalSumSy] ORDER BY T3.[ItemCode]
2°
SELECT T1.[ItemCode], T1.[Dscription], T0.[CardCode], T0.[CardName], Cantidad=sum(T1.[Quantity]), T1.[unitMsr], Total=sum(T1.[TotalSumSy]) FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocType]<>'S' and T0.[DocDate]>='[%0]' and T0.[DocDate]<='[%1]' GROUP BY T1.[ItemCode], T1.[Dscription], T0.[CardCode], T0.[CardName], T1.[Quantity], T1.[unitMsr], T1.[TotalSumSy] ORDER BY T1.[ItemCode]
Ojala alguien me pueda ayudar
Gracias
1°
SELECT T3.[ItemCode], T3.[Dscription], T2.[CardCode], T2.[CardName], Cantidad=sum(T3.[Quantity]), T3.[unitMsr], Total=sum(T3.[TotalSumSy]) FROM [dbo].[OINV] T2 INNER JOIN [dbo].[INV1] T3 ON T2.DocEntry = T3.DocEntry WHERE T2.[DocType]<>'S' and T2.[DocDate] >= '[%0]' and T2.[DocDate] <= '[%1]' GROUP BY T3.[ItemCode], T3.[Dscription], T2.[CardCode], T2.[CardName], T3.[Quantity], T3.[unitMsr], T3.[TotalSumSy] ORDER BY T3.[ItemCode]
2°
SELECT T1.[ItemCode], T1.[Dscription], T0.[CardCode], T0.[CardName], Cantidad=sum(T1.[Quantity]), T1.[unitMsr], Total=sum(T1.[TotalSumSy]) FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocType]<>'S' and T0.[DocDate]>='[%0]' and T0.[DocDate]<='[%1]' GROUP BY T1.[ItemCode], T1.[Dscription], T0.[CardCode], T0.[CardName], T1.[Quantity], T1.[unitMsr], T1.[TotalSumSy] ORDER BY T1.[ItemCode]
Ojala alguien me pueda ayudar
Gracias