本文介紹了XQuery 檢索值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我有以下 T-SQL 使用兩個條件確定行是否存在:
I have the following T-SQL that determines if a row exists using two criteria:
Declare @x xml = '
<row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="page" itemValue="Confirmation" itemType="string" />
<row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="visited" itemValue="false" itemType="bool" />'
SELECT @x.exist('/row[@Node eq "root.local.navigation[7]"] and /row[@itemValue eq "Confirmation"]')
問題:鑒于上面的 SELECT,我如何選擇第二行的 itemValue?即,由于有一行 Node="root.local.navigation[7]" 和 itemValue="Confirmation",在 node 相同且 itemKey="visited" 的行中返回 itemType 值?
Question: Given the above SELECT, how can I SELECT the second row's itemValue? i.e. Since there's a row with Node="root.local.navigation[7]" and itemValue="Confirmation", return the itemType value in the row where node is the same and itemKey="visited"?
推薦答案
這個怎么樣:
declare @x xml = '
<row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="page" itemValue="Confirmation" itemType="string" />
<row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="visited" itemValue="false" itemType="bool" />'
select case when @x.exist('/row[@Node eq "root.local.navigation[7]"] and /row[@itemValue eq "Confirmation"]') = 1
then @x.value('/row[@Node eq "root.local.navigation[7]" and @itemKey eq "visited"][1]/@itemType', 'varchar(50)')
end as item_type
這篇關(guān)于XQuery 檢索值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!