我目前正在使用 T-SQL 将一些数据转换为 XML。我需要在自己的行上列出属性的值。由于某种原因,T-SQL 到 XML 不断将值连接在同一行上。
示例代码:
SELECT
'Fruits' AS [Attribute/@name],
'Apple' AS [Attribute/Value],
'Orange' AS [Attribute/Value],
'Grape' AS [Attribute/Value]
FOR XML PATH (''), ROOT('CustomProduce'), TYPE
结果示例:
<CustomProduce>
<Attribute name="Fruits">
<Value>AppleOrangeGrape</Value>
</Attribute>
</CustomProduce>
期望的结果:
<CustomProduce>
<Attribute name="Fruits">
<Value>Apple</Value>
<Value>Orange</Value>
<Value>Grape</Value>
</Attribute>
</CustomProduce>
任何帮助将不胜感激,非常感谢!
一种(相当荒谬的)方法,以防没人知道更好的解决方案:
SELECT
'Fruits' AS [Attribute/@name],
'' AS [Attribute],
'Apple' AS [Attribute/Value],
'' AS [Attribute],
'Orange' AS [Attribute/Value],
'' AS [Attribute],
'Grape' AS [Attribute/Value]
FOR XML PATH (''), ROOT('CustomProduce'), TYPE
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)