SELECT YEAR(SH.TARIH) AS YIL,MONTH(SH.TARIH) AS AY,DEPO.KODU AS DEPOKODU,SH.STOKKODU,ST.STOKADI, 
SUM(CASE WHEN SH.GDEPO=DEPO.KODU THEN SH.ADET ELSE 0 END) GIRENADET, 
SUM(CASE WHEN SH.CDEPO=DEPO.KODU THEN SH.ADET ELSE 0 END) CIKANADET,  
SUM(CASE WHEN SH.GDEPO=DEPO.KODU THEN SH.ADET ELSE 0 END)-SUM(CASE WHEN SH.CDEPO=DEPO.KODU THEN SH.ADET ELSE 0 END) AS KALANADET,  
(ISNULL(SUM(CASE WHEN SH.GDEPO=DEPO.KODU THEN SH.ADET ELSE 0 END),0)-ISNULL(SUM(CASE WHEN SH.CDEPO=DEPO.KODU THEN SH.ADET ELSE 0 END),0)) 
FROM DEPO 
LEFT JOIN STOKHAREKET SH ON SH.GDEPO=DEPO.KODU OR SH.CDEPO=DEPO.KODU   
LEFT JOIN STOK ST ON ST.STOKKODU=SH.STOKKODU   
GROUP BY YEAR(SH.TARIH),MONTH(SH.TARIH),DEPO.ADI,DEPO.KODU,SH.STOKKODU,ST.STOKADI  
ORDER BY 2,4