This question already has an answer here:
-
New line in Sql Query
4 answers
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
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
Try this
DECLARE @firstName NVARCHAR(50)
, @lastName NVARCHAR(50)
, @text NVARCHAR(MAX)
DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
SELECT @text = 'First Name : ' + @firstName + @NewLineChar + 'Second Name : ' + @lastName
PRINT @Text
CHAR(13)
will show the text in new line, when you switch to Result to text
.
You need to add CHAR(13)
between your two string.
SELECT @text nvarchar(MAX) = 'First Name : ' + @firstName + CHAR(13) + ' Second Name : ' + @secondName