SQL Server XML Processing: Join different Nodes based on ID(SQL Server XML 处理:根据 ID 加入不同的节点)
问题描述
我正在尝试使用 SQL 查询 XML.假设我有以下 XML.
我想编写一个返回 2 行的 SELECT 查询,如下所示:
我目前的做法如下:
我不喜欢这里的是我必须使用 OUTER APPLY
两次,而且我必须使用 WHERE
子句来 JOIN
正确的元素.
因此我的问题是: 是否有可能以我不必以这种方式使用 WHERE
子句的方式构造查询,因为我是可以肯定的是,如果文件变大,这会对性能产生非常负面的影响.
难道不能用一些XPATH语句JOIN
正确的节点(即对应的generalData
和specialData
节点)?
您的 XPath 表达式完全关闭.
请尝试以下操作.这是非常有效的.您可以使用大型 XML 测试其性能.
<块引用>SQL
<块引用>
输出
I am trying to query XML with SQL. Suppose I have the following XML.
I want to write a SELECT query that returns 2 rows as follows:
My current approach is as follows:
What I do not like here is that I have to use OUTER APPLY
twice and that I have to use the WHERE
clause to JOIN
the correct elements.
My question therefore is: Is it possible to construct the query in a way where I do not have to use the WHERE
clause in such a way, because I am pretty sure that this affects performance very negatively if files become larger.
Shouldn't it be possible to JOIN
the correct nodes (that is, the corresponding generalData
and specialData
nodes) with some XPATH statement?
Your XPath expressions are completely off.
Please try the following. It is pretty efficient. You can test its performance with a large XML.
SQL
Output
这篇关于SQL Server XML 处理:根据 ID 加入不同的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!