查询SQL SERVER中的XML跳过布尔值

时间:2014-02-17 01:10:02

标签: sql-server xml tsql

简单来说,我只是想查询XML列(下面):

  1. 我正在跳过旁边有一个星号的行
  2. 只对旁边有两个星号的行感兴趣

    -falsefalse * 真正* 假* 真正** 假** 假 假 假 假 假 假 假 假 假 假 假 假 假

1 个答案:

答案 0 :(得分:0)

试试这个,如果不行,那么解释你的标准

Declare @i xml='<?xml version="1.0"?>-<ArrayOfBoolean xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><boolean>false</boolean><boolean>false</boolean>
<boolean>true</boolean><boolean>false</boolean><boolean>true</boolean><boolean>false</boolean><boolean>false</boolean><boolean>false</boolean>
<boolean>false</boolean><boolean>false</boolean><boolean>false</boolean><boolean>false</boolean><boolean>false</boolean><boolean>false</boolean>
<boolean>false</boolean><boolean>false</boolean><boolean>false</boolean><boolean>false</boolean><boolean>false</boolean></ArrayOfBoolean>'

;with cte as
(select *,ROW_NUMBER()over(order by  (SELECT 0))rn from
(SELECT  col1 = col1.value('.', 'bit') 

FROM   
         @i.nodes('/ArrayOfBoolean/boolean') AS tag ( col1 ))tbl
)

select * from cte where rn>(select max(rn)+1 from cte where col1=1)