I am using SQL Server 2008
我正在使用SQL Server 2008
I have a table with xml data looks like:
我有一个xml数据表如下:
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>
I want to get those records that
我想得到那些记录
'when attribute=17 then value =1'+ 'when attribute=8 then value='AAA''
How can i create the query and how to build xml indexes?
如何创建查询以及如何构建xml索引?
Thank you very much.
非常感谢你。
1 个解决方案
#1
5
To select all rows which have the criteria you mentioned, try this select statement:
要选择具有您提到的条件的所有行,请尝试以下select语句:
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'
For XML indices, read up on Books Online how to create them and how to use them.
对于XML索引,请阅读联机丛书如何创建它们以及如何使用它们。
#1
5
To select all rows which have the criteria you mentioned, try this select statement:
要选择具有您提到的条件的所有行,请尝试以下select语句:
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'
For XML indices, read up on Books Online how to create them and how to use them.
对于XML索引,请阅读联机丛书如何创建它们以及如何使用它们。