Arkadaşlar aşağıdaki query'de DEVIR CARPIM ile SATINALMA CARPIM sonuçlarını nasıl toplatıp sonuç kısmına yazabilirim.
SELECT ITEMS.CODE AS MLZKOD, ITEMS.NAME AS MLZAD, ST.INVENNO AS AMBAR, SUM(ROUND(ST.ONHAND, 2)) AS MIKTAR, MONTH(ST.DATE_) AS TARIH,
ROUND(DEV.Expr1, 2) AS [DEVIR FIYAT], ROUND(SONALIS.SATINALMAFIYAT, 2) AS SATINALMAFIYAT, SUM(ROUND(ST.ONHAND, 2)) * ROUND(DEV.Expr1, 2)
AS [DEVIR CARPIM], CASE WHEN ROUND(DEV.Expr1, 2) IS NULL THEN SUM(ROUND(ST.ONHAND, 2)) * ROUND(SONALIS.SATINALMAFIYAT, 2)
END AS [SATINALMA CARPIM]
FROM dbo.LG_086_ITEMS AS ITEMS LEFT OUTER JOIN
dbo.LG_086_01_STINVTOT AS ST ON ITEMS.LOGICALREF = ST.STOCKREF LEFT OUTER JOIN
(SELECT STOCKREF, ROUND(VATMATRAH / AMOUNT, 2) AS Expr1
FROM dbo.LG_086_01_STLINE
WHERE (TRCODE = '14') AND (CANCELLED = '0') AND (LINETYPE = '0')
GROUP BY STOCKREF, ROUND(VATMATRAH / AMOUNT, 2)) AS DEV ON ITEMS.LOGICALREF = DEV.STOCKREF LEFT OUTER JOIN
(SELECT ST.STOCKREF, ROUND(ST.VATMATRAH / ST.AMOUNT, 2) AS SATINALMAFIYAT
FROM dbo.LG_086_01_STLINE AS ST LEFT OUTER JOIN
(SELECT MAX(LOGICALREF) AS LOG, STOCKREF
FROM dbo.LG_086_01_STLINE AS LG_086_01_STLINE_1
WHERE (TRCODE = '1') AND (CANCELLED = '0') AND (LINETYPE = '0') AND (VATMATRAH > 0)
GROUP BY STOCKREF) AS A ON A.LOG = ST.LOGICALREF
WHERE (ST.LINETYPE = '0') AND (ST.CANCELLED = '0') AND (ST.TRCODE = '1')) AS SONALIS ON ITEMS.LOGICALREF = SONALIS.STOCKREF
WHERE (ST.INVENNO IN (21))
GROUP BY ITEMS.CODE, ITEMS.NAME, ST.INVENNO, MONTH(ST.DATE_), ROUND(DEV.Expr1, 2), ROUND(SONALIS.SATINALMAFIYAT, 2)