本文介紹了使用 t-SQL 檢索 XML 元素名稱的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如果我有:
<quotes>
<quote>
<name>john</name>
<content>something or other</content>
</quote>
<quote>
<name>mary</name>
<content>random stuff</content>
</quote>
</quotes>
如何使用 T-SQL 獲取元素名稱名稱"和內容"的列表?
How do I get a list of the element names 'name' and 'content' using T-SQL?
到目前為止我得到的最好的是:
The best I've got so far is:
declare @xml xml
set @xml = ...
select r.value('quotes/name()[1]', 'nvarchar(20)' as ElementName
from @xml.nodes('/quotes') as records(r)
但是,當然,我不能讓它工作.
But, of course, I can't get this to work.
推薦答案
實際上,抱歉,我得到的最好的是:
Actually, sorry, the best I've got is:
select distinct r.value('fn:local-name(.)', 'nvarchar(50)') as t
FROM
@xml.nodes('//quotes/*/*') AS records(r)
猜猜我回答了我自己的問題...
Guess I answered my own question...
這篇關于使用 t-SQL 檢索 XML 元素名稱的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!