• I am sorry the code should be:

    
    
    Create FUNCTION GetCol4 (@col1 datatype, @col2 datatype, @col3 datatype)RETURNS varchar(5000)AS
    BEGIN
    DECLARE @Cols varchar(5000)
    SET @Cols = ''

    SELECT @Cols =
    CASE @Cols
    WHEN '' THEN col4
    ELSE @Cols + ', ' + col4
    END
    FROM sample
    where col1 = @col1
    and col2 = @col2
    and col3 = @col3

    RETURN(@Cols)