Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Carriage return in Select query

Author  Topic 

Dinky
Starting Member

37 Posts

Posted - 2008-04-23 : 15:10:19
How to get a carriage return (or new line) in the result of select query.

Example: Select 'a' + 'b'
display
a
b

and not ab

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-23 : 15:12:37
SELECT 'a' + CHAR(10) + CHAR(13) + 'b'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Dinky
Starting Member

37 Posts

Posted - 2008-04-23 : 17:05:12
SELECT 'a' + CHAR(10) + CHAR(13) + 'b'
does not work
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-23 : 17:09:03
Yes it does. Perhaps you are viewing your data in the grid mode. To see the formatting, you need to display it in text.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Dinky
Starting Member

37 Posts

Posted - 2008-04-23 : 17:56:09
I run it in SQL server 2005 management studio and then copy the results into notepad. It does not display a and b in 2 lines - just a b
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-23 : 18:03:21
see results in text view. Go query-results to -text
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-23 : 18:13:50
quote:
Originally posted by Dinky

I run it in SQL server 2005 management studio and then copy the results into notepad. It does not display a and b in 2 lines - just a b



You must switch to text mode first. Once in text mode, you'll see the carriage return and can copy/paste into notepad to see it too.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-24 : 03:33:09
quote:
Originally posted by sodeep

see results in text view. Go query-results to -text


or Press CONTROL+T

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-24 : 03:52:24
And if you don't want an empty line between A and B, switch order of CHAR(10) and CHAR(13)

SELECT 'A' + CHAR(13) + CHAR(10) + 'B'


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -