Sql 查询中的新行

如何在 Sql 查询中获得新的换行或换行?

289660 次浏览

Pinal Dave explains this well in his blog.

http://blog.sqlauthority.com/2009/07/01/sql-server-difference-between-line-feed-n-and-carriage-return-r-t-sql-new-line-char/

DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
PRINT ('SELECT FirstLine AS FL ' + @NewLineChar + 'SELECT SecondLine AS SL')

You could do Char(13) and Char(10). Cr and Lf.

Char() works in SQL Server, I don't know about other databases.

use CHAR(10) for New Line in SQL
char(9) for Tab
and Char(13) for Carriage Return

-- Access:
SELECT CHR(13) & CHR(10)


-- SQL Server:
SELECT CHAR(13) + CHAR(10)