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

CREATE FUNCTION [dbo].[MEDWEB_DOKTORBILGILERI]  
(    
    @DRID int
)
RETURNS @DRINFO TABLE 
(
	
	MAXRANDEVUGUNSAYI int,
	ALTYASSINIRI int,
	USTYASSINIRI int,
	KONTROLLLERIRANDEVUSUZALIR int,
	WEBMAXRANDEVUGUNSAYI int
) 
AS
BEGIN
	INSERT @DRINFO SELECT ISNULL(MAXRANDEVUGUNSAYI,0) AS MAXRANDEVUGUNSAYI,ISNULL(ALTYASSINIRI,199) AS ALTYASSINIRI,ISNULL(USTYASSINIRI,0) AS USTYASSINIRI,(CASE WHEN KONTROLLLERIRANDEVUSUZALIR=1 THEN 1 ELSE 0 END) AS  KONTROLLLERIRANDEVUSUZALIR, ISNULL(WEBMAXRANDEVUGUNSAYI,0) AS WEBMAXRANDEVUGUNSAYI  FROM TDRKIMLIK WHERE DRID=@DRID
    RETURN
END
go

IF EXISTS (SELECT [name] FROM [sys].[database_principals] WHERE [type] = N'S' AND [name] = N'mediwebuser')
BEGIN
	BEGIN TRY
		GRANT SELECT ON [dbo].[MEDWEB_DOKTORBILGILERI] TO [mediwebuser]
	END TRY
	BEGIN CATCH
	END CATCH
END
GO