本文介紹了從 sum 中刪除一個 xml 節點,在 XPath 到 SQL Server XML 列中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有這個 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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!