CREATE FUNCTION [dbo].[fn_STUD_1_GetPrepMathsTeachers](
	@name VARCHAR(50)
	,@surname VARCHAR(50)
	,@year VARCHAR(4)
)
RETURNS VARCHAR(200)
AS
BEGIN

RETURN
(SELECT	STUFF((SELECT DISTINCT ',' + Prep2017_SessionReviewTool_MathsTeachers 
                FROM	dbo.qt_PrepProgramme2017 
				WHERE	Prep2017_SessionReviewTool_Name = @name
						AND Prep2017_SessionReviewTool_Surname = @surname
						AND Prep2017_SessionReviewTool_PrepProgrammeYear = @year
						AND Prep2017_SessionReviewTool_Date <= GETDATE()
						AND Prep2017_SessionReviewTool_MathsTeachers <> ''
            FOR XML PATH(''), TYPE
            ).value('.', 'NVARCHAR(MAX)') 
        ,1,1,'')
)
END



GO


