Ver Mensaje Individual
  #4 (permalink)  
Antiguo 21/10/2013, 13:15
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: Como sumar 2 columnas de una misma linea

Código SQL:
Ver original
  1. SELECT TRIM,Corte1,UMC1,SUM(Ton1)Ton1,Descripcion,Id_Contenedor,Ancho,UAncho,TrimCorte,Peso,Rollos,
  2. CASE WHEN corte8=corte9 THEN Ton8+Ton9  END AS toneladas
  3. FROM(
  4.  
  5. SELECT DISTINCT TRIM,Corte1,UMC1,Ton1 FROM protri01 WHERE PedPipsa1 = '2070713'
  6. UNION SELECT DISTINCT  TRIM,Corte2,UMC2,Ton2 FROM protri01 WHERE PedPipsa2 ='2070713'
  7. UNION SELECT DISTINCT TRIM,Corte3,UMC3,Ton3 FROM protri01 WHERE PedPipsa3 = '2070713'
  8. UNION SELECT DISTINCT  TRIM,Corte4,UMC4,Ton4 FROM protri01 WHERE PedPipsa4 ='2070713'
  9. UNION SELECT DISTINCT TRIM,Corte5,UMC5,Ton5 FROM protri01 WHERE PedPipsa5 = '2070713'
  10. UNION SELECT DISTINCT TRIM,Corte6,UMC6,Ton6 FROM protri01 WHERE PedPipsa6 ='2070713'
  11. UNION SELECT DISTINCT TRIM,Corte7,UMC7,Ton7 FROM protri01 WHERE PedPipsa7 = '2070713'
  12. UNION SELECT DISTINCT TRIM,Corte8,UMC8,Ton8 FROM protri01 WHERE PedPipsa8 ='2070713'
  13. UNION SELECT DISTINCT TRIM,Corte9,UMC9,Ton9 FROM protri01 WHERE PedPipsa9 = '2070713'
  14. UNION SELECT DISTINCT TRIM,Corte10,UMC10,Ton10 FROM protri01 WHERE PedPipsa10 ='2070713'
  15. UNION SELECT DISTINCT TRIM,Corte11,UMC11,Ton11  FROM protri01 WHERE PedPipsa11 = '2070713'
  16. UNION SELECT DISTINCT TRIM,Corte12,UMC12,Ton12 FROM protri01 WHERE PedPipsa12 ='2070713' ) C
  17. INNER JOIN
  18. (SELECT DISTINCT Descripcion,Id_Contenedor,Ancho,UAncho,TRIM AS TrimCorte,SUM(Peso) Peso ,COUNT(Id_Lote) Rollos
  19. FROM    prolot01  A INNER JOIN  catpap01 B ON B.Id_Papel = A.Id_Papel
  20. WHERE   PedidoPIPSA= '2070713'AND Peso > 0 AND DevProd = 0 AND Jagenberg = 0 AND Detenido = 0 AND Rechazado = 0
  21. GROUP BY Id_Contenedor,Ancho,UAncho,A.TRIM,B.Descripcion)D
  22. ON  C.TRIM = D.TrimCorte AND Corte1 = Ancho AND UMC1 = UAncho  GROUP BY TRIM,Corte1,UMC1,Descripcion,Id_Contenedor,Ancho,UAncho,TrimCorte,Peso,Rollos
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me