SQL SERVER : How to make query from XML file(SQL SERVER:如何从 XML 文件进行查询)
问题描述
我有两个这样的 xml 文件:
I have two xml file like this:
还有
下面是我解析xml文件的sqlquery:
Below is my sqlquery for parsing xml file:
如果
不可用,如何进行查询,结果应该是这样的:
How to make Query if <Defect>
not available and the result should like this:
我对 xml 查询不太熟悉,似乎找不到如何执行此操作的示例.任何帮助,将不胜感激.谢谢
I'm not real familiar with xml query and can't seem to find an example of how to do it. Any help would be appreciated. Thanks
推荐答案
我猜你的动态查询在那里是因为你不知道默认的命名空间.相反,您可以使用 *
在 XQuery 中指定名称空间.
I guess that your dynamic query is there because the default namespace is unknown to you. Instead you can specify the namespace in the XQuery using *
.
使用父轴 ..
可以通过在几个步骤中使用 nodes()
和 cross apply
分解 XML 来避免.由于 Defect
节点可能会丢失,因此在粉碎这些节点时必须使用 outer apply
.
Using the parent axis ..
can be avoided by shredding the XML using nodes()
and cross apply
in several steps. Since the Defect
node can be missing you have to use outer apply
when shredding those nodes.
SQL 小提琴
这篇关于SQL SERVER:如何从 XML 文件进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!