sql server 2000 和 xml 显式
我在 SQL Server 2000 中显式使用 for xml 时遇到问题(因此我无法使用 sql 2005/8 中的新 path() 内容)
本质上我有两个表,我想要的 XML 结构
<xml>
<table_1 field1="foo" field2="foobar2" field3="foobar3">
<a_row_from_table_2 field1="goo" field2="goobar2" field3="goobar3" />
<a_row_from_table_2 field1="hoo" field2="hoobar2" field3="hoobar3" />
</table_1>
</xml>
是,table_1与table_2是一对多的关系,我想将它建立一个层次结构。
到目前为止我似乎无法得到它,我设法得到的最接近的是表1中的所有记录,表2中的所有记录附加到表1的最后一个元素
任何有关设置这种关系的帮助都会不胜感激。
-马尔辛
I've got a problem with using for xml explicit in SQL Server 2000 (so I can't use the new path() stuff from sql 2005/8)
Essentially I have two tables and the XML structure I want to have is
<xml>
<table_1 field1="foo" field2="foobar2" field3="foobar3">
<a_row_from_table_2 field1="goo" field2="goobar2" field3="goobar3" />
<a_row_from_table_2 field1="hoo" field2="hoobar2" field3="hoobar3" />
</table_1>
</xml>
That is, table_1 has a one-to-many relationship with table_2, and I want to make a hierarchy of it.
So far I can't seem to get it, the closest I've managed to get is all the records from table1, with all the records from table2 appended to the very last element of table1
Any help with setting up this kind of relationship would be greatly appreciated.
-Marcin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的查询是否包含
order by
子句?在for xml 显式
模式中,信息按所需顺序出现非常重要。例如,在 Northwind 示例数据库中,您可以为员工区域生成嵌套 XML,如下所示:这会生成如下 XML:
要了解其工作原理,请在不使用
for xml 显式的情况下运行查询
。Does your query include an
order by
clause? Infor xml explicit
mode, it's important that information appears in the sequence it's needed. For example, in the Northwind example database, you can generate a nested XML for employee territories like:This results in an XML like:
To get an idea of how it works, run the query without the
for xml explicit
.