Kod: Tümünü seç
Stok
kod-int
ad-varchar
StokHar
islemno-bigint
kod-int
tarih-date
gmik-int
cmik-int
aşağıdaki kod ile stokhar tablosundan ürünlerin aylık giriş ve çıkış toplamlarını hesaplatmaya çalışıyorum.
Kod: Tümünü seç
SET TERM ^ ;
CREATE PROCEDURE SP_STOKHARAYLIK (
STKD1 INTEGER,
STKD2 INTEGER)
AS
begin
select yk.kod,yk.ad,
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=1) "OcakGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=1) "OcakCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=2) "SubatGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=2) "SubatCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=3) "MartGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=3) "MartCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=4) "NisanGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=4) "NisanCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=5) "MayısGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=5) "MayısCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=6) "HaziranGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=6) "HaziranCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=7) "TemmuzGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=7) "TemmuzCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=8) "AgustosGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=8) "AgustosCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=9) "EylulGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=9) "EylulCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=10) "EkimGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=10) "EkimCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=11) "KasimGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=11) "KasimCik",
(select sum(gmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=12) "AralıkGir",
(select sum(cmik) from stokhar yk1 where yk.kod=yk1.kod and extract(month from tarih)=12) "AralıkCik"
from stok yk where (yk.kod between :stkd1 and :stkd2)
group by kod,ad order by kod,ad
suspend;
end
^
SET TERM ; ^
iki sorum olacak;
1-yukarıdaki kod sql editörde çalışıyor fakat bunu SP yapayım dedim olmadı. procedure` ü compile edince "suspend" ifadesini tanımıyor. "order by kod,ad" dan sonra ";" koydum. bu sefer ";" ü tanımadı. bunun için ne yapabilirim. Bir çok şey denedim ama başaramadım.
2-yukarıdaki kodu kısaltmanın bir yolu var mı? left outer join ile yapmayı denedim fakat çok acayip sonuçlar verdi.
Kolay gelsin. iyi çalışmalar..