alt text http://img248.imageshack.us/img248/1797/updatetable.png
使用每个OrderId的CategoryCode更新Combined列。在这个例子中有两个OrderIds 990和986.需要单独连接这两个类别。
期望的结果是这样的。
990 Bus, Pub, Shoot, Club, Bus, Hos
感谢。
答案 0 :(得分:0)
UPDATE test
SET combined = Left(j.combined, Len(j.combined) - 1)
FROM test t
JOIN (SELECT a.orderid,
(SELECT categorycode + ','
FROM test b
WHERE b.orderid = a.orderid
ORDER BY orderid
FOR XML PATH('')) AS combined
FROM test a
GROUP BY orderid) AS j
ON j.orderid = t.orderid