本文介紹了使用 t-SQL 檢索 XML 元素名稱(chēng)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
如果我有:
<quotes>
<quote>
<name>john</name>
<content>something or other</content>
</quote>
<quote>
<name>mary</name>
<content>random stuff</content>
</quote>
</quotes>
如何使用 T-SQL 獲取元素名稱(chēng)名稱(chēng)"和內(nèi)容"的列表?
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)
但是,當(dāng)然,我不能讓它工作.
But, of course, I can't get this to work.
推薦答案
實(shí)際上,抱歉,我得到的最好的是:
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)
猜猜我回答了我自己的問(wèn)題...
Guess I answered my own question...
這篇關(guān)于使用 t-SQL 檢索 XML 元素名稱(chēng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!