我有这个 XPath 表达式,它对最深的 XML 层次结构中的所有节点求和,而不使用节点名称:
I have this XPath expression, which sum all nodes in the deepest XML hierarchy, without using nodes names:
select @data.value('sum(//*[not(*)])', 'float')
如何根据名称对一个节点进行例外处理?
How do I make an exception of one node, by its name?
说这是xml:
<c>
<b1>
<a>1</a>
<d>4</d>
<g>5</g>
</b1>
<b1>
<a>7</a>
<d>1</d>
<g>2</g>
</b1>
</c>
我希望总和包含d"和g",没有a",但a"将作为参数传递,因此需要在表达式中表示为参数.我尝试了以下方法:
I would like the sum to contain "d" and "g", without "a", but "a" will be pass as parameter and so need to be represented as parameter inside the expression. I've tried the following:
declare @except varchar(max) = 'a'
select @data.value('sum(//*[not(*)])', 'float') - @data.value('sum(//*:local-name()=sql:variable("@except"))', 'float')
但没有成功.
虽然 Marc 的回答是我最会做的,但我有一个小技巧给你,下面
While Marc's answer is what i would do mostly, I have a small hack for you, below
select @data.value('sum(//*[not(*)])', 'float')- @data.value('sum(//*:a)', 'float')
这篇关于从 sum 中删除一个 xml 节点,在 XPath 到 SQL Server XML 列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
我可以在不编写 SQL 查询的情况下找出数据库列表Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不编写 SQL 查询的情况下
如何创建对 SQL Server 实例的登录?How to create a login to a SQL Server instance?(如何创建对 SQL Server 实例的登录?)
如何通过注册表搜索知道SQL Server的版本和版本How to know the version and edition of SQL Server through registry search(如何通过注册表搜索知道SQL Server的版本和版本)
为什么会出现“数据类型转换错误"?使用 ExWhy do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(为什么会出现“数据类型转换错误?使用 ExecuteNonQuery()?)
如何将 DataGridView 中的图像显示到 PictureBox?How to show an image from a DataGridView to a PictureBox?(如何将 DataGridView 中的图像显示到 PictureBox?)
WinForms 应用程序设计——将文档从 SQL Server 移动WinForms application design - moving documents from SQL Server to file storage(WinForms 应用程序设计——将文档从 SQL Server 移动到文件存