Add preceding wording to SQL results.

bfuchs
bfuchs used Ask the Experts™
on
Hi Experts,
I have the following formula, and would like to precede it with some wording (for example 'Here is your list'), in case the formula returns something, how can I do it?
SELECT snv_id = STUFF((
SELECT ', ' + snv_id + ' ' + CONVERT(VARCHAR(10), Visit_Date, 101) + ' ' + Client_Last_Name + ' ' + ' ' + Client_First_name + char(10) 
FROM _v_v_VisitNotes_Browser
where _v_v_VisitNotes_Browser.nurse_User_ID_num_SNV= '[@authfield:Nurse_UserName]'
FOR XML PATH('')
), 1, 1, '')

Open in new window

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
Simple string concatenation?

SELECT snv_id = 'Here is your list' + STUFF((
...

Open in new window

Hi,

And what is if I want add Char(10) after the wording?

What is the rule of string concatenation?

One more Q (if you dont mind-:)

The current list is giving me
 SNV103409 11/26/2019 A.  B.
, SNV103411 11/27/2019 A.  B.
, SNV103418 11/29/2019 A.  B

Open in new window

How can I change that to
 SNV103409 11/26/2019 A.  B.,
SNV103411 11/27/2019 A.  B.,
SNV103418 11/29/2019 A.  B

Open in new window

but for one record, no comma?

Thanks,
Ben
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
>>How can I change that to

Append the comma AFTER the value?

>>but for one record, no comma?

A case statement:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6dc6daa4-7366-4f8d-8c61-0f3406b00b87/remove-last-comma-from-the-string?forum=transactsql

CASE 
	WHEN RIGHT(RTRIM(f1),1) = ',' THEN LEFT(f1,LEN(f1)-1)
	ELSE f1
	END AS f1

Open in new window

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial