Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/08/2011, 10:23
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: Ayuda!¿Como uno estas dos consultas?

A lo que veo puedes hacer lo sig:

Código SQL:
Ver original
  1. SELECT
  2. T0.DocNum AS Oferta,
  3. T1.SlpName AS Comercial,
  4. T2.Zipcode AS CP,
  5. T2.City AS Poblacion
  6. INTO #temp
  7. FROM
  8. OQUT T0 LEFT JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
  9. LEFT JOIN CRD1 T2 ON T0.CardCode = T2.CardCode
  10. WHERE
  11. T0.Series = '613' AND T2.Address LIKE 'FACTUR%'
  12.  
  13.  
  14. SELECT
  15. STR (Cuentas1.Neto/Cuentas1.Coste,10,3) AS FMT,
  16. STR (Cuentas2.Neto/Cuentas2.Coste,10,3) AS FMO
  17. FROM (
  18. SELECT
  19. SUM(T1.LineTotal) AS Neto,
  20. SUM(T1.GrossBuyPr*T1.Quantity) AS Coste
  21. FROM
  22. OQUT T0 INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry
  23. WHERE
  24. T0.DocNum EXISTS (SELECT * FROM #temp) AND T1.Itemcode NOT IN ('10000025','99999999')
  25. ) AS Cuentas1,
  26. (
  27. SELECT
  28. SUM(T1.LineTotal) AS Neto,
  29. SUM(T1.GrossBuyPr*T1.Quantity) AS Coste
  30. FROM
  31. OQUT T0 INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry
  32. WHERE
  33. T0.DocNum EXISTS (SELECT * FROM #temp) AND T1.Itemcode ='10000025'
  34. ) AS Cuentas2

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