RAPORLAMA ÖNCESİ ÇALIŞACAK SORGU :
DELETE ATARIH WHERE ID=1
INSERT INTO ATARIH (ID,BASTAR,BITTAR)
VALUES (1,{FLTDATEVAL(1)},{FLTDATEVAL(2)})
RAPOR SORGUSU
select I.GTIPCODE, P.BASTAR, P.BITTAR,
DEVIRTUT= CASE WHEN DAY(P.BASTAR)=1 AND MONTH(P.BASTAR)=1 THEN
ROUND(ISNULL((SELECT SUM(L.AMOUNT*M.GIRBFYT)
FROM LG_118_01_STLINE L
LEFT OUTER JOIN LA_118_MALMALIYET M ON M.MALREF=L.STOCKREF
INNER JOIN LG_118_ITEMS A ON A.LOGICALREF=L.STOCKREF
WHERE L.CANCELLED=0 AND L.LINETYPE=0 AND L.TRCODE=14 AND L.CANCELLED=0 AND A.GTIPCODE=I.GTIPCODE),0),0)
ELSE
ROUND(ISNULL((SELECT SUM(CASE WHEN L.TRCODE IN (1,2,3,4,5,13,14,50) THEN (L.AMOUNT*M.GIRBFYT) ELSE ((L.AMOUNT*-1)*M.GIRBFYT) END)
FROM LG_118_01_STLINE L
LEFT OUTER JOIN LA_118_MALMALIYET M ON M.MALREF=L.STOCKREF
INNER JOIN LG_118_ITEMS A ON A.LOGICALREF=L.STOCKREF
WHERE L.CANCELLED=0 AND L.LINETYPE=0 AND L.LINETYPE=0 AND L.CANCELLED=0 AND A.GTIPCODE=I.GTIPCODE AND L.DATE_<P.BASTAR),0),0) END
.....
FROM LG_118_ITEMS I
INNER JOIN ATARIH P ON P.ID=1
WHERE I.ACTIVE=0 AND (SELECT TOP 1 S.LOGICALREF FROM LG_118_01_STLINE S
WHERE S.STOCKREF=I.LOGICALREF AND S.CANCELLED=0 AND S.LINETYPE=0
AND S.DATE_<=P.BITTAR) IS NOT NULL
GROUP BY I.GTIPCODE,P.BASTAR,P.BITTAR
işlemi bu kadar sıkıntılı olması GROUP BY işlevinden kaynaklanmakta.
GROUP BY bazı yöntemleri sorgu içinde kullandırmamakta.
Bundan dolayı ancak bu yöntem çalışıyor.