Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/08/2012, 10:02
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 3 meses
Puntos: 774
Respuesta: Union y resta de dos querys

Código SQL:
Ver original
  1. SELECT campo1-campo2 AS campo_resta FROM(
  2.  
  3. 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]
  4. UNION
  5. 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]
  6. ) tabla
algo asi :)

saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me