1

I would like to add a new line in SELECT statement in SSMS. how can it be done? I wanted to display the output as

No columnname
---------
1
2

I tried

select '1'+CHAR(13)+CHAR(10)+'2'

It showing the o/ p as

No

columnname
---------
1 2

But did not help..

Please advice

Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
  • it is coming as 1 2 .Please explain your problem well – mohan111 Jul 13 '18 at 13:34
  • 1
    SSMS doesn't matter as much as the output of your application. What are you trying to do with this data? Is it for a report, or do you just want to see a new line there? – Shawn Jul 13 '18 at 13:36
  • This also contains some useful information: https://stackoverflow.com/questions/2679481/ssms-results-to-grid-crlf-not-preserved-in-copy-paste-any-better-techniques – Tab Alleman Jul 13 '18 at 13:58
  • Yes its for a report.. that comes in the top of the report.I pass static data and the second set of data has to be in the second line – Passiontolearn Jul 13 '18 at 14:24

3 Answers3

2

Your method of select '1'+CHAR(13)+CHAR(10)+'2' was correct... you simply need to change the results to text instead of grid. It's a button on the toolbar. In Grid mode, this is still one row, thus it's in the first row.

It's the left button in these three:

Results

SSMS Example

S3S
  • 24,809
  • 5
  • 26
  • 45
0

This would be work with print command or you can also copy the whole text & pase into notepad to see desired result.

print '1'+CHAR(13)+CHAR(10)+'2'
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
0

Try this :

select v 
from ( values (1), (2), (3)
     ) val(v)
mohan111
  • 8,633
  • 4
  • 28
  • 55