IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MEDWEB_KONTROLMUAYENEMI]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].[MEDWEB_KONTROLMUAYENEMI]
GO

CREATE FUNCTION [dbo].[MEDWEB_KONTROLMUAYENEMI]  
(   
	@HTCKIMLIKNO VARCHAR(15), 
    @DRID int,
	@RANDTATIH smalldatetime
)
RETURNS @KONTROL TABLE 
(
	
	KONTROL int
) 
AS
BEGIN
	
	IF (SELECT COUNT(HMUAYENEID) FROM VWMUAYENE WHERE HTCKIMLIKNO=@HTCKIMLIKNO  AND HMDRID=@DRID AND HMTARIH>DATEADD(DAY,-12,GETDATE()) AND DATEADD(DAY,10,HMTARIH)>@RANDTATIH) > 0 
		INSERT INTO  @KONTROL SELECT 1
	ELSE
		INSERT INTO @KONTROL SELECT 0
	
    RETURN
END
