
select S1.StokKodu,S1.Depo ,(
SELECT ISNULL(SUM(Miktar*(CASE GC WHEN 'G' THEN 1 WHEN 'C' THEN -1 END)), 0) FROM STOKHAR S2 where S2.StokKodu=S1.StokKodu and S2.Depo=S1.Depo
) Miktar from  STOKHAR S1 where FaturaTarihi<'20220101'  
group by S1.Depo,S1.StokKodu
