user1557443
user1557443

Reputation: 29

How to store "new line" in SQL Server 2008 R2

I want to use new line in my select query

For example:

SELECT
    FULLNAME + ADDRESS AS X1
FROM 
    TBL_USERS

and the result should be something like this:

ABBAS KOLAHDOOZAN
ISFAHAN,BOZORGMEHR ST

as a single column.

I use CHAR(10), CHAR(13) but that dont work.

Does anyone have a working solution?

Upvotes: 1

Views: 1924

Answers (2)

Dinesh Reddy Alla
Dinesh Reddy Alla

Reputation: 1717

DECLARE @name VARCHAR(MAX)= 'ABBAS KOLAHDOOZAN'
DECLARE @town VARCHAR(MAX)= 'ISFAHAN,BOZORGMEHR ST'
DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)

PRINT( @name + @NewLineChar + @town)

Upvotes: 0

StuartLC
StuartLC

Reputation: 107277

The Sql

SELECT
 FULLNAME + CHAR(13) + CHAR(10) + ADDRESS AS X1
FROM
TBL_USERS;

Will insert a Windows CRLF between the columns. What you might be seeing is SSMS's Output to Grid results, which will eat whitespace. Switch to Text results mode if you want to see the actual result.

Upvotes: 5

Related Questions