简体   繁体   中英

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?

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM