I have table values in this format
sam
jack
sam
john
Declare @name varchar(max)
select @name = COALESCE(@name + ', ','')+ user_email
from PostedCommentMaster where article_id = @id
How can I get distinct value
sam,jack,john
like this.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can wrap the select statement into a subselect and apply coalesce on the results.
Note that this uses an undocumented feature of SQL Server to concatenate the results into one string. While I can’t find a link to it anymore, I recall reading that your should not rely on this behavior.
A better alternative would be to use the
FOR XMLsyntax to return a concatenated string. A search on SO returns multiple results you can use as an example.