Answer the question
In order to leave comments, you need to log in
How to combine text from multiple lines into one text line?
Table
AZone2Adapter].[dbo].[_data_OrganizationCustomerSpecialties] ( [Id], [OrganizationCustomerId], [SpecialtyId])
How to display all columns with a condition in a script.?DECLARE @TextProduct NVARCHAR(MAX);
SELECT @TextProduct = ISNULL(@TextProduct + ', ','') + QUOTENAME([OrganizationCustomerId])
FROM [AZone2Adapter].[dbo].[_data_OrganizationCustomerSpecialties]
WHERE [OrganizationCustomerId]='1002775640209670'
SELECT @TextProduct AS TextProduct
If you write:SELECT @TextProduct = ISNULL(@TextProduct + ', ','') + QUOTENAME([OrganizationCustomerId]),[Id]
STRING_AGG
does not work, only for SQL Server 2017
Answer the question
In order to leave comments, you need to log in
CONCAT
DECLARE @TextProduct NVARCHAR(MAX);
SELECT @TextProduct = CONCAT_WS( ', ', @TextProduct, [OrganizationCustomerId])
FROM [AZone2Adapter].[dbo].[_data_OrganizationCustomerSpecialties]
WHERE [OrganizationCustomerId]='1002775640209670'
SELECT @TextProduct AS TextProduct
Microsoft SQL Server 2008
DECLARE @TextProduct NVARCHAR(MAX);
SELECT @TextProduct = STUFF(COALESCE(', ' + @TextProduct, '')
+ COALESCE(', ' + [OrganizationCustomerId], ''), 1, 2, '')
FROM [AZone2Adapter].[dbo].[_data_OrganizationCustomerSpecialties]
WHERE [OrganizationCustomerId]='1002775640209670'
SELECT @TextProduct AS TextProduct
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question