Last post Jul 14, 2020 08:29 AM by Sean Fang
Jul 14, 2020 07:09 AM|Gopi.MCA|LINK
I have one filed Which has following Data
I want result set
How to get like this data i have more then 2000 records
Jul 14, 2020 08:29 AM|Sean Fang|LINK
Here is a workaround with SQL query statement.
I have below data in the database:
The sql statement is :
Declare @Numbers AS Nvarchar(MAX)
SELECT @Numbers = COALESCE(@Numbers + ',', '') + '''' + [name] + ''''
I understand that there are some methods like using XML and STRING_AGG. However, XML is not easier to understand and use. STRING_AGG requires SQL SERVER 2017 or later.
If you are interested in above two methods, you could refer to here: How to concatenate text from multiple rows
into a single text string in SQL server?
Hope this can help you.