Seminerdeki SQL kod:
Kod: Tümünü seç
select @dlr_firma_no=firma_no
from gelen_fatura
where gelen_fatura=@gelen_fatura
Malum SP şu şekilde :
Kod: Tümünü seç
ALTER PROCEDURE SPI_GELEN_FATURA_URUN (
gelen_fatura_no integer,
urun_no integer,
adet integer,
birim_fiyat numeric(4,2))
as
declare variable dlr_kayit_sayisi integer;
declare variable dlr_firma_no integer;
begin
select count(*) from URUN_STOK
where URUN_NO = :URUN_NO
INTO DLR_KAYIT_SAYISI;
if (DLR_KAYIT_SAYISI=0) then
insert into URUN_STOK(URUN_NO,TOPLAM_GIRIS,TOPLAM_CIKIS) values(:URUN_NO,0,0);
update URUN_STOK set
TOPLAM_GIRIS = toplam_giris+:adet where
URUN_NO = :URUN_NO;
(bu şekilde derlemeye çalıştım ama, beceremedim)
select count(*)
from gelen_fatura
where gelen_fatura_no =:gelen_fatura_no
INTO DLR_KAYIT_SAYISI;
select count(*)
from FIRMA_HESAP
where FIRMA_NO = :dlr_firma_no
INTO DLR_KAYIT_SAYISI;
if (DLR_KAYIT_SAYISI=0) then
insert into FIRMA_HESAP(FIRMA_NO,TOPLAM_BORC,TOPLAM_ALACAK) values(:dlr_firma_no,0,0);
update FIRMA_HESAP set
TOPLAM_ALACAK = TOPLAM_ALACAK+:ADET*:birim_fiyat where
FIRMA_NO = :dlr_firma_no;
end
Malum Trigger ise şu şekilde:
Kod: Tümünü seç
ALTER TRIGGER gelen_fatura_urun_ai0
active after insert position 0
AS
begin
execute procedure spi_gelen_fatura_urun ( new.gelen_fatura_no,NEW.URUN_NO, NEW.adet,new.birim_fiyat);
end