Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/07/2013, 15:28
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Duda con esta consulta

con los datos que mencionas puedes hacer esto :)

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. articulo INT,
  4. depo INT,
  5. cant INT,
  6. mes INT,
  7. signo INT
  8. )
  9.  
  10. INSERT INTO #temp VALUES (1,1 ,10, 3, -1)
  11. INSERT INTO #temp VALUES (1, 1, 15, 3, -1)
  12. INSERT INTO #temp VALUES (1, 1, 20, 4, 1)
  13. INSERT INTO #temp VALUES (1, 2, 15, 6, 1)
  14. INSERT INTO #temp VALUES (2, 2, 12, 6, 1)
  15. INSERT INTO #temp VALUES (2, 3, 12, 7, 1 )
  16. INSERT INTO #temp VALUES (2, 3, 15, 7, -1)
  17.  
  18. SELECT articulo,depo,mes,SUM(cantidad) AS total FROM(
  19. SELECT articulo,depo,mes,(cant*signo) AS cantidad FROM #temp) AS t1 GROUP BY articulo,depo,mes

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