stok_bakiye.sql 449 B

12345678910
  1. set @dbakiye := 0;
  2. set @iscari := '@merkez@';
  3. set @stkod := '@stokod@';
  4. select
  5. round(sum(giris-cikis),2) as bakiye from(
  6. select
  7. case when (ftip='C' and hedef=@iscari) or (ftip='G' and kaynak=@iscari) then miktar else 0 end as giris,
  8. case when ftip='C' and kaynak=@iscari or (ftip='G' and hedef=@iscari) then miktar else 0 end as cikis
  9. from sthar where stok_kodu=@stkod and (hedef=@iscari or kaynak=@iscari) and tarih<='@tarih@'
  10. )as t;