I am trying to concatenate many columns and separating it with a comma as below:
Column
------
abc
bcd
bgd
abc
Expected output: abc,bcd,bgd
I am using this code:
CREATE FUNCTION concatinate(@PK uniqueidentifier)
RETURNS varchar(max)
AS
BEGIN
DECLARE @result varchar(max)
SELECT @result = ISNULL(@result + ', ', '') + Column
FROM table
The result I am getting is
abc,bcd,bgd,abc
I am not able to only select the distinct values. Please guide.