$1 View [dbo].[Magazalar_OdemeTipi_Ciro]
as
SELECT
		ISNULL(mgz_isim,'') [isim],
		ISNULL(odm_aciklama,'')[Tip],
		(SUM(CASE WHEN evr_belge_tur in (1,2) THEN evr_yekun ELSE 0 END))-(SUM(CASE WHEN evr_belge_tur in (3) THEN evr_yekun ELSE 0 END)) as [Tutar]
FROM
		EVRAK_UST_BILGI WITH(NOLOCK)
LEFT OUTER JOIN EVRAK_ODEME_BILGI WITH(NOLOCK) on odmhar_evrak_rec_id = evr_RECno
LEFT OUTER JOIN ODEME_TIPLERI WITH(NOLOCK) on odm_kod = odmhar_odeme_kod and odm_magazano= evr_magaza_kod
LEFT OUTER JOIN MAGAZA_TANIMLARI WITH(NOLOCK) on mgz_kod = evr_magaza_kod 


WHERE 
		evr_belge_tur in (1,2,3)
group by 
		mgz_isim,odm_tip,odm_aciklama,mgz_kod