0

我正在使用 XML PATH 绑定多值列,查询工作正常,但结果是 xml 格式,我想将其转换为简单文本这是查询

 SELECT soo.order_id,
 sum(oo.total)AS total,
 items=(SELECT si.item_name FROM sub_order i,Items si
 WHERE i.order_id=soo.order_id and si.item_id=i.item_id  FOR XML PATH(''))
 FROM Orders oo
 INNER JOIN Sub_Order soo ON oo.order_id = soo.order_id
 INNER JOIN Items
 ON soo.item_id = Items.item_id 
 group by soo.order_id

“项目”字段的结果就像

 <item_name>cake</item_name><item_name>soap</item_name>

但我希望它像 cake,soap

4

1 回答 1

2

代替

items=(SELECT si.item_name FROM sub_order i,Items si
 WHERE i.order_id=soo.order_id and si.item_id=i.item_id  FOR XML PATH(''))

items=STUFF((SELECT ',' + si.item_name FROM sub_order i,Items si
 WHERE i.order_id=soo.order_id and si.item_id=i.item_id  FOR XML PATH('')),1,1,'')
于 2013-11-13T10:44:55.867 回答