Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line in sql server [duplicate]

I am using an procedure to Select First-name and Last-name

declare 
    @firstName nvarchar(50),
    @lastName nvarchar(50),
    @text nvarchar(MAX)

SELECT @text = 'First Name : ' + @firstName + ' Second Name : ' + @lastName 

The @text Value will be sent to my mail But the Firstname and Lastname comes in single line. i just need to show the Lastname in Second line

O/P First Name : Taylor Last Name : Swift ,
I need the output like this below format

First Name : Taylor 
Last Name : Swift
like image 267
GeoVIP Avatar asked Aug 30 '13 08:08

GeoVIP


People also ask

How do I add a new line in SQL Server?

Insert SQL carriage return and line feed in a string In SQL Server, we can use the CHAR function with ASCII number code. We can use the following ASCII codes in SQL Server: Char(10) – New Line / Line Break. Char(13) – Carriage Return.

What does \n mean in SQL?

Background. The "N" prefix stands for National Language in the SQL-92 standard, and is used for representing Unicode characters. In the current standard, it must be an upper case , which is what you will typically find implemented in mainstream products.

How do I replace a new line character in SQL?

CHR(10) is used to insert line breaks, CHR(9) is for tabs, and CHR(13) is for carriage returns. In the example above, we wanted to remove all occurrences of the line break, of the tab, and of the carriage return, so we used CHR(10) , CHR(9) , and CHR(13) .

How do I duplicate a row in SQL?

To select duplicate values, you need to create groups of rows with the same values and then select the groups with counts greater than one. You can achieve that by using GROUP BY and a HAVING clause.


2 Answers

You may use

CHAR(13) + CHAR(10)
like image 152
Giannis Paraskevopoulos Avatar answered Oct 07 '22 10:10

Giannis Paraskevopoulos


Try to use CHAR(13) -

DECLARE 
      @firstName NVARCHAR(50) = '11'
    , @lastName NVARCHAR(50) = '22'
    , @text NVARCHAR(MAX) 

SELECT @text = 
    'First Name : ' + @firstName + 
    CHAR(13) + --<--
    'Second Name : ' + @lastName

SELECT @text

Output -

First Name : 11
Second Name : 22
like image 43
Devart Avatar answered Oct 07 '22 08:10

Devart