Wednesday, June 22, 2011

SQL SERVER - T-SQL New Line Character

To print information like multi line address, we have to use new line character. Different operating systems have different ways to understand this new line character. Mac supports only '\r' where as Linux supports '\n' and the most popular OS Windows needs both of these characters to understand the new line which is '\r\n'.

Few synonyms for line feed (LF) and carriage return(CR) are listed as below

Line Feed – LF – \n – 0x0a – 10 (decimal)
Carriage Return – CR – \r – 0x0D – 13 (decimal)

E.g.
Without new line character

DECLARE @NewLineCharacter CHAR(2) = CHAR(13) + CHAR(10)
PRINT 'Address1 Address2'
GO
Result:
Address1 Address2

With new line character

DECLARE @NewLineCharacter CHAR(2) = CHAR(13) + CHAR(10)
PRINT 'Address1 ' + NewLineCharacter  +'Address2'
GO
Result:
Address1
Address2




No comments:

Post a Comment