本文介紹了如何在 SQL Server 2008 中查詢 XML 列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我使用的是 SQL Server 2008
I am using SQL Server 2008
我有一個包含 xml 數據的表,如下所示:
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''
如何創建查詢以及如何構建 xml 索引?
How can i create the query and how to build xml indexes?
非常感謝.
推薦答案
要選擇具有您提到的條件的所有行,請嘗試以下選擇語句:
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'
對于 XML 索引,請閱讀在線書籍 如何創建它們以及如何使用它們.
For XML indices, read up on Books Online how to create them and how to use them.
這篇關于如何在 SQL Server 2008 中查詢 XML 列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!