sqlservice2005 xml字段查询的空值问题

在对sqlserver2005的xml字段进行查询时发现:查询结果如果为空,显示的速度会很慢

例如:

select* from table 
where fbfw.exist('/Root/Person[.=''xxx'' and @checked=\"0\"]')=1 

 或者

select * from table
where fbfw.value('(/Root/Person[@checked = 0][text()='xxx''])[1]', 'varchar(10)')
 is not null 

测试后发现可能是xml查询条件有2个的关系,于是改为

select * from table
where fbfw.query('/Root/Person[text()=''xxx'']').exist('/Person[@checked = 0]')=1

 查询时间明显减少。这种写法是根据一个条件查询出符合条件的节点,再判断节点中的属性值。

猜你喜欢

转载自li-hy2002.iteye.com/blog/1488471
今日推荐