0

We want to display multiple column value into the single column with comma separated value below is the my table data

enter image description here

Below is the SQL query i am trying:

 select name, STUFF((SELECT '; ' + facilty FROM leads Name FOR XML PATH('')),1,2,'') as facilty, address from leads 

Query Result

enter image description here

Now when I execute the query in SQL Server, I want reuslt to be like:

enter image description here

2 Answers 2

2

Use string_agg():

select max(name), string_agg(facility, ','), max(address) from leads group by leadid; 
Sign up to request clarification or add additional context in comments.

2 Comments

Would be helpful to mention that STRING_AGG is supported only if you are using SQL Server version 2017 and higher
@PriyankPanchal . . . It was released three years ago and isn't even the current version.
0

Use where clause :

select name , STUFF((SELECT '; ' + facilty FROM leads FOR XML PATH('') ),1,2,'') as facilty, address from leads where name is not null; 

1 Comment

this working fine i know. is not null condition is working but i want some other method to do this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.