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
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.
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.
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) .
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.
You may use
CHAR(13) + CHAR(10)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With