Inserting New Line Characters into Strings in SQL Server

Q

How To Insert New Line Characters into Strings in SQL Server Transact-SQL?

✍: FYIcenter.com

A

If you want to break a string into multiple lines, you need to insert new line characters into the string. With some client tools like SQL Server Management Studio, it is not so easy to insert a new line character.

One work around is to use the CHAR(int) function to generated new line character and other special characters with their code values:

  • CHAR(9) - Generates the tab character.
  • CHAR(10) - Generates the line feed (new line) character.
  • CHAR(13) - Generates the carriage return character.

The tutorial examples below gives you a good example

PRINT 'Welcome to '+CHAR(10)+'FYIcenter.com';
PRINT CHAR(10);
PRINT 'Current date and time is '
   +CONVERT(VARCHAR(20), GETDATE());
GO
Welcome to 
FYIcenter.com


Current date and time is May 19 2007  7:30PM

 

Character Strings and Binary Strings in SQL Server Transact-SQL

⇒⇒SQL Server Transact-SQL Tutorials

2017-03-07, 186👍, 0💬