In this tutorial, we will learn how to concatenate the
multiple rows for a single column value into a single string text SQL server. I am using the Northwind database table “Customers”
and the column name is “ContactName”. And here is the query
SELECT CONTACTNAME FROM
CUSTOMERS
DECLARE @STR NVARCHAR(MAX)
SELECT @STR = COALESCE(@STR + ',','') + C.CONTACTNAME FROM CUSTOMERS C
PRINT @STR
SELECT @STR AS [STR
OUTPUT]
Result:-
No comments:
Post a Comment
Please do not enter spam links.