user2115618
user2115618

Reputation: 183

SQL Server : Add Comma to the Select statement

I wanted to add comma between VM.Address and VM.City in the below select query

DECLARE @Address NVARCHAR(MAX);
set @Address = ' SELECT  [Address] = CONCAT(VM.Address,' ', VM.City) 

FROM  [dbo].[VendorMaster] VM
    WHERE IsActive = 1 AND VendorID = 6
ORDER BY VendorName'

EXECUTE SP_EXECUTESQL @Address

Upvotes: 0

Views: 461

Answers (2)

NewSQL
NewSQL

Reputation: 181

Try by using comma within quotes in middle of Address and City :

set @Address = ' SELECT  [Address] = CONCAT(VM.Address,'+''','''+', VM.City) 

Upvotes: 3

Rahul Tripathi
Rahul Tripathi

Reputation: 172518

Try

set @Address = ' SELECT  [Address] = STUFF(VM.Address + COALESCE(', ' + VM.City, '') , 1, 2, '')

Upvotes: 0

Related Questions