2015-12-28 61 views
0

我想在下面選擇查詢VM.Address和VM.City之間添加逗號SQL服務器:添加逗號SELECT語句

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 

回答

3

嘗試通過在地址和城市中間使用逗號引用:

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

謝謝。有效 – user2115618

0

嘗試

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