buenos días, por favor alguien que me ayude con esta consulta me solicitaron realizar un informe de costos- gasto e ingresos en SAP por proyectos y por mes es decir que por mes me muestre los proyectos el costo e gasto y el ingreso
gracias por su ayuda
tengo esta consulta pero me trae es el total por proyecto y no por mes
SELECT PrjCode AS proyecto, PrjName, ISNULL
((SELECT SUM(tt0.Debit) - SUM(tt0.Credit) AS Expr1
FROM dbo.JDT1 AS tt0 LEFT OUTER JOIN
dbo.OJDT AS tt1 ON tt0.TransId = tt1.TransId
WHERE (tt0.Project = t11.PrjCode) AND (tt0.Account LIKE '5%')
GROUP BY tt0.Project), 0) AS Gasto, ISNULL
((SELECT SUM(tt0.Debit) - SUM(tt0.Credit) AS Expr1
FROM dbo.JDT1 AS tt0 LEFT OUTER JOIN
dbo.OJDT AS tt1 ON tt0.TransId = tt1.TransId
WHERE (tt0.Project = t11.PrjCode) AND (tt0.Account LIKE '7%')
GROUP BY tt0.Project), 0) + ISNULL
((SELECT SUM(tt0.Debit) - SUM(tt0.Credit) AS Expr1
FROM dbo.JDT1 AS tt0 LEFT OUTER JOIN
dbo.OJDT AS tt1 ON tt0.TransId = tt1.TransId
WHERE (tt0.Project = t11.PrjCode) AND (tt0.Account LIKE '6%')
GROUP BY tt0.Project), 0) AS Costo,
(SELECT (SUM(tt0.Debit) - SUM(tt0.Credit)) * - 1 AS Expr1
FROM dbo.JDT1 AS tt0 LEFT OUTER JOIN
dbo.OJDT AS tt1 ON tt0.TransId = tt1.TransId
WHERE (tt0.Project = t11.PrjCode) AND (tt0.Account LIKE '4%')
GROUP BY tt0.Project) AS Ingreso
FROM dbo.OPRJ AS t11
GROUP BY PrjCode, PrjName