if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[HRAPOR_DR_LISTE]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[HRAPOR_DR_LISTE]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

IF EXISTS(SELECT NAME FROM SYS.tables WHERE NAME='HRAPORDR')
BEGIN
    EXEC ('CREATE FUNCTION [dbo].[HRAPOR_DR_LISTE] (@HRAPORID as Int)  
    RETURNS nvarchar(1000) AS  
    BEGIN
	    RETURN STUFF((
		    SELECT '', ''+ISNULL(DRADI, '''') + '' '' + ISNULL(DRSOYADI, '''') 
		    FROM HRAPORDR WITH(NOLOCK)
		    WHERE HRAPORID = @HRAPORID
		    FOR XML PATH('''')
	    ) ,1,2,'''' )
    END')
END