Código SQL:
Ver originalCREATE TABLE #table
(
articulo VARCHAR(2),
movimiento INT,
entrada_salida VARCHAR(2),
cantidad INT)
INSERT INTO #table VALUES ('A',1,'E',20)
INSERT INTO #table VALUES ('B',1,'E',30)
INSERT INTO #table VALUES ('C',1,'E',10)
INSERT INTO #table VALUES ('A',2,'S',5)
INSERT INTO #table VALUES ('A',2,'S',3)
SELECT
SUM(isnull(entrada,0)) AS entrada, SUM(isnull(salida,0)) AS salida, articulo
FROM(
SELECT
CASE
WHEN entrada_salida='S' THEN SUM(cantidad) END AS salida,
CASE
WHEN entrada_salida='E' THEN SUM(cantidad) END AS entrada,
articulo
FROM #table GROUP BY articulo,entrada_salida
) AS t1 GROUP BY articulo
Saludos!!