
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[MEDWEB_AKTIFDOKTORLAR]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION [dbo].MEDWEB_AKTIFDOKTORLAR
GO
CREATE FUNCTION [dbo].[MEDWEB_AKTIFDOKTORLAR](@SUBEID int, @BOLUMID int) 
RETURNS @retSUBEDOKTORLAR TABLE 
(
	DRID int,
	DRADI nvarchar(50), 
	MAXRANDEVUGUNSAYI int
)
AS
BEGIN
	INSERT INTO @retSUBEDOKTORLAR
	SELECT DRID, (CASE WHEN ISNULL(DRUNVAN,'')='' THEN  DRADI ELSE DRUNVAN + ' ' + DRADI END) AS DRADI, MAXRANDEVUGUNSAYI FROM TDRKIMLIK WHERE BOLUMID = @BOLUMID AND SUBEID = @SUBEID AND STATUS = 'A' AND WEBRANDEVUVERILIR=1
    RETURN
END
GO
