0

I have string variable like this

declare @string nvarchar(200) 
set @string = N'table1,table2,table3' 

and I want to change comma on new line to have every table in new line.

I'm trying something like this but it doesn't work

 select replace(@string,',',char(13))
NewMe
  • 35
  • 1
  • 8
  • What doesn't work? What you posted does what you wrote - put each string in a separate line in the text. It won't split the string or convert the single string to multiple rows. Tables aren't files and table rows aren't text lines – Panagiotis Kanavos Apr 12 '19 at 10:20
  • If you want to split the string, `STRING_SPLIT` was introduced in SQL Server 2016 – Panagiotis Kanavos Apr 12 '19 at 10:21

1 Answers1

0

it should work. Depending on your system you should consider using char(13) + char(10) Line feed: char(10) Carriage return: char(13)

declare @string nvarchar(200) 
set @string = N'table1,table2,table3' 
print replace(@string,',',char(13) + char(10))

if you copy it from your SSMS Result table it may remove the lines

Manfred Wippel
  • 1,946
  • 1
  • 15
  • 14