如何查询行及其 xml 表示形式?
我需要类似的东西
select * from tb_listings for xml auto
,但我需要每一行都是分开的,而不是一个大的 xml 文档。
我尝试过类似以下的操作:
select id, (select * from tb_listings a where a.id=id for xml auto) as xmldata from tb_listings
预期输出如下:
id xmldata
------------------------------------------------------------
1 <listing><name>ABC</name><xyz>123</xyz></listing>
但它似乎没有达到我想要的效果,而且还需要很长时间才能运行。
任何想法将不胜感激。 :)
编辑:想通了:
select id, (select top 1 * from tb_listings a where a.id=b.id for xml auto) from tb_listings b
结束。
I need something like
select * from tb_listings for xml auto
But I need every row to be separate, and not one big xml document.
I have tried something like the following:
select id, (select * from tb_listings a where a.id=id for xml auto) as xmldata from tb_listings
Expected output is like:
id xmldata
------------------------------------------------------------
1 <listing><name>ABC</name><xyz>123</xyz></listing>
But it doesn't seem to do what I want and it also takes a very long time to run.
Any ideas would be appreciated. :)
Edit: Figured it out:
select id, (select top 1 * from tb_listings a where a.id=b.id for xml auto) from tb_listings b
Closing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的事情:
输出:
try something like this:
OUTPUT: