Ana stok ve çeşitlerin miktar toplamları farklı olan stokları bulmak için aşağıdaki kod çalıştırılmalıdır.
execute block
returns(
xstok_k k,xaltstok_k type of k, xstokmiktar miktar, xstokgiris miktar, xstokcikis miktar,xaltstokmiktar miktar, xaltstokgiris miktar, xaltstokcikis miktar, xmiktarfark miktar)
as
begin
for select k from stok where cesitvar=1 into :xstok_k do
begin
xstokmiktar = 0;
select miktar,giris,cikis from stokmiktar where konum_k=1 and stok_k=:xstok_k into :xstokmiktar, :xstokgiris, :xstokcikis;
xaltstokmiktar = 0;
select coalesce(sum(sm.miktar),0), coalesce(sum(sm.giris),0),coalesce(sum(sm.cikis),0) from stokmiktar sm join stok s on sm.konum_k=1 and sm.stok_k=s.k and s.ustk=:xstok_k into :xaltstokmiktar, :xaltstokgiris, :xaltstokcikis;
xmiktarfark = :xstokmiktar-:xaltstokmiktar;
if (xmiktarfark <> 0) then
suspend;
end
end