久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

XML to SQL 問題 - 如何獲取元素的位置

XML to SQL Issue - How to get position of an element(XML to SQL 問題 - 如何獲取元素的位置)
本文介紹了XML to SQL 問題 - 如何獲取元素的位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我試圖在 sql 中獲取 XML 節點元素的位置,但它沒有給我正確的結果,@Shungo 建議使用該方法

I am trying to get the position of an element of an XML node in sql , and it is not giving me correct results , the approach was suggested by @Shungo

這是代碼:

declare @xmlVar xml ='
<A specVersion="2.09">
  <B id="1" type="Regular">
    <C>
      <D>
        <E actioncode="A" date="06/13/2018 09:20" />
        <E  actioncode="B" date="06/13/2018 09:20" />
      </D>
      <D>
        <E actioncode="C" date="06/13/2018 09:20" />
      </D>
    </C>
  </B>

  <B id="2" type="Regular">
    <C>
      <D>
        <E  actioncode="D" date="06/13/2018 09:20" />
      </D>
    </C>
  </B>
</A>' ;
    WITH Tally(Nmbr) AS
(
    SELECT TOP (SELECT @xmlVar.value(N'count(/A/B/C/D)','int'))
           ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) 
    FROM master..spt_values --just a pre-filled table with many rows
)
SELECT Nmbr
      ,e.value(N'@actioncode[1]','nvarchar(max)') AS Employee
FROM Tally
OUTER APPLY(SELECT @xmlVar.query(N'/A/B/C/D[sql:column("Nmbr")]')) AS A(ds)
OUTER APPLY ds.nodes(N'D/E') AS B(e);

上面的查詢給出了錯誤的結果:

The above query is giving wrong results :

1   A
1   B
1   D
2   C
3   NULL

預期輸出:

1  A
1  B
2  C
3  D

任何幫助將不勝感激.謝謝.

Any help would be appreciated . Thanks.

推薦答案

嗯,這和之前的完全不一樣了...

Well, this is quite different to the one before...

看起來,您希望將 <D> 節點放在任何位置.這有幫助嗎?

As it looks, you want to take <D> nodes whereever they are placed. Does this help?

WITH Tally(Nmbr) AS
(
    SELECT TOP (SELECT @xmlVar.value(N'count(//D)','int'))
           ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) 
    FROM master..spt_values --just a pre-filled table with many rows
)
SELECT Nmbr
      ,e.value(N'@actioncode[1]','nvarchar(max)') AS Employee
FROM Tally
OUTER APPLY(SELECT  @xmlVar.query(N'//D').query(N'/D[sql:column("Nmbr")]')) AS B(ds)
OUTER APPLY ds.nodes(N'D/E') AS C(e);

第一個應用程序將使用深度搜索(使用//D)來獲取僅包含這些節點的派生 XML.其余的和以前一樣.

The first apply will use the deep search (with //D) to get a derived XML including these nodes only. The rest is rather the same as before.

這篇關于XML to SQL 問題 - 如何獲取元素的位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日本人做爰大片免费观看一老师 | 久久久精| 91精品国产高清久久久久久久久 | 国产盗摄视频 | 91免费在线看 | 欧美一级片久久 | 久久综合狠狠综合久久综合88 | 超碰在线免费公开 | 国内精品视频在线观看 | 精品视频一区二区三区在线观看 | 五月天国产 | 我要看免费一级毛片 | 视频一区二区在线观看 | 99久久久久久 | 一级h片| 久久久久精 | 欧美日韩视频网站 | av天天操| 美女在线国产 | 久久精品中文 | 亚洲国产精品99久久久久久久久 | 亚洲444eee在线观看 | 一区二区视频在线 | 久久久青草婷婷精品综合日韩 | 男女羞羞视频免费 | 久久综合婷婷 | 国产不卡在线观看 | 成人在线观看中文字幕 | 亚洲 欧美 精品 | 日韩在线视频一区二区三区 | 日本黄色免费大片 | 国产精品久久久久不卡 | 亚洲成人三级 | 国产精品一区免费 | 亚洲午夜精品 | 亚洲天堂网站 | 暖暖成人免费视频 | 久久久久久高潮国产精品视 | 欧美日韩国产一区二区三区 | 欧美aⅴ在线观看 | 日韩在线不卡视频 |