$1  FUNCTION [dbo].[fn_SadakatKartPuan] (@kartNo varchar(100)='',@oran float)
RETURNS float
AS
BEGIN--0:Nakit 1:Kredi 2:AcikHesap 3:SmartCard 4:SadakatKart
DECLARE @VAL As Float
IF(@kartNo='' or @kartNo is null)
	RETURN ROUND(@VAL,2)
BEGIN
SELECT TOP 1 @VAL= SUM(
CASE 
	WHEN odm_tip in (0,1) THEN  odmhar_tutar*(@oran/100)
	WHEN odm_tip=4 THEN (-1)*odmhar_tutar
	ELSE 0 END)
FROM EVRAK_UST_BILGI 
LEFT OUTER JOIN EVRAK_ODEME_BILGI ON odmhar_evrak_rec_id=evr_RECno
LEFT OUTER JOIN ODEME_TIPLERI ON odm_kod=odmhar_odeme_kod AND odm_magazano=evr_magaza_kod
WHERE evr_sadakat_kart_no=@kartNo
END
IF @VAL is NULL OR @VAL<0 SET @VAL=0
RETURN ROUND(@VAL,2)
END
