本文介紹了如何在 SQL Server 2008 中查詢 XML 列的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我使用的是 SQL Server 2008
I am using SQL Server 2008
我有一個(gè)包含 xml 數(shù)據(jù)的表,如下所示:
I have a table with xml data looks like:
ID xml_col
1 <Attribute id="7">1.0</Attribute><Attribute id="8">AAA</Attribute>
2 <Attribute id="7">2.0</Attribute><Attribute id="8">BBB</Attribute>
3 <Attribute id="7">3.0</Attribute><Attribute id="8">AAA</Attribute>
4 <Attribute id="7">1.0</Attribute><Attribute id="8">BBB</Attribute>
5 <Attribute id="7">1.0</Attribute><Attribute id="8">AAA</Attribute>
6 <Attribute id="7">7.0</Attribute><Attribute id="8">CCC</Attribute>
我想得到那些記錄
'when attribute=17 then value =1'+ 'when attribute=8 then value='AAA''
如何創(chuàng)建查詢以及如何構(gòu)建 xml 索引?
How can i create the query and how to build xml indexes?
非常感謝.
推薦答案
要選擇具有您提到的條件的所有行,請(qǐng)嘗試以下選擇語(yǔ)句:
To select all rows which have the criteria you mentioned, try this select statement:
SELECT *
FROM dbo.YourXmlTable
WHERE
YourXmlTable.xml_col.value('(//Attribute[@id=7])[1]', 'decimal') = 1.0
AND
YourXmlTable.xml_col.value('(//Attribute[@id=8])[1]', 'varchar(10)') = 'AAA'
對(duì)于 XML 索引,請(qǐng)閱讀在線書(shū)籍 如何創(chuàng)建它們以及如何使用它們.
For XML indices, read up on Books Online how to create them and how to use them.
這篇關(guān)于如何在 SQL Server 2008 中查詢 XML 列的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!