1

I have two string in sql server 2008 r2 query. I want to make new line between these strings like and I tried to do all with char() like below, but I'm still not success.
Could you show me any thing else. thanks!!!!!!!

declare @text1 varchar(20) = 'First';   
declare @text2 varchar(20) = 'Last';

declare @string1 varchar(40)= @text1 + char(10) + @text2  
select @string1;  

declare @string2 varchar(40)= @text1 + char(13) + @text2  
select @string2;  

declare @string3 varchar(40)= @text1 + char(10) + char(13) + @text2  
select @string3;  

declare @string4 varchar(40)= @text1 + char(12) + @text2  
select @string4;
jpw
  • 44,361
  • 6
  • 66
  • 86
  • 1
    I'm guessing you're executing your queries in SMSS with output set to grid. Change output to text and you'll see the line breaks are indeed there, except for the last (char(12) ) – jpw Sep 28 '14 at 19:29
  • Ow! Like you say, thanks. but if i want to make a new line in SMSS how can i do. – Nheom Phearum Sep 28 '14 at 19:35

2 Answers2

2
declare @string5 varchar(40)= @text1 + char(13) + char(10) + @text2;
select @string5;

Or, alternatively:

declare @string6 varchar(40)= @text1 + '
' + @text2;
select @string6;
Roger Wolf
  • 7,307
  • 2
  • 24
  • 33
0

For this you can use ASCII character of carriage return char(39) (I forgot the exact no.) if you want it as a html <br> or \n while concatenating the string.

gofr1
  • 15,741
  • 11
  • 42
  • 52
Ajay2707
  • 5,690
  • 6
  • 40
  • 58