FOR XML PATH 多筆資料合併為一筆
SELECT [SalesOrderID],
(
SELECT [ProductID] + ',' FROM [sales].[SalesOrderDetail] as s2
WHERE s1.SalesOrderID=s2.SalesOrderID
FOR XML PATH('')
) as ProductID
FROM [sales].[SalesOrderDetail] as s1
group by [SalesOrderID],[ProductID]
--
數字跟字串欄位作字串串接
cast([ProductID] as nvarchar)
全站熱搜
留言列表