How to query on XML column In SQL Server 2008(如何在 SQL Server 2008 中查询 XML 列)
问题描述
我使用的是 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 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 SQL Server 2008 中查询 XML 列


基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01