1

MyColumn 列のテーブル セルに次の xml があります。

<BSDL xmlns="..." xmlns:i="...">
  <dateTime>2012-12-30T00:00:00Z</dateTime>
  <dateTime>2013-01-07T00:00:00Z</dateTime>
  <dateTime>2013-01-14T00:00:00Z</dateTime>
  <dateTime>2013-01-21T00:00:00Z</dateTime>
  <dateTime>2013-01-29T00:00:00Z</dateTime>
  <dateTime>2013-02-05T00:00:00Z</dateTime>
  <dateTime>2013-02-12T00:00:00Z</dateTime>
  <dateTime>2013-02-19T00:00:00Z</dateTime>
  <dateTime>2013-03-22T00:00:00Z</dateTime>
  <dateTime>2013-03-29T00:00:00Z</dateTime>
  <dateTime>2013-04-19T00:00:00Z</dateTime>
</BSDL>  

次を使用してクエリを実行しようとしています(すべてのxmlノードを取得します):

SELECT BSDL.item.value('(dateTime)[1]', 'datetime')
    from [MyTable]
    CROSS APPLY [MyColumn].nodes ('//BSDL') BSDL(item)  

my MyColumnin にMyTableは、各行に対して上記と同じ数のエントリがありますが、結果は得られません。

4

1 に答える 1

1

Since there's only one <BSDL> node - your call to //BSDL selects that single node and then item.value('(dateTime)[1]', 'datetime') returns the first <dateTime> child.

You need to change your XQuery to (use that xmlns=.... namespace you mention in your sample here):

;WITH XMLNAMESPACES('.....' as ns)
SELECT 
    item.value('.', 'datetime')
from 
    dbo.MyTable
CROSS APPLY 
    MyColumn.nodes ('/ns:BSDL/ns:dateTime') BSDL(item)  

You need to get a list of all <dateTime> nodes under <BSDL> - then you'll get all of them and you can inspect them one by one.

于 2013-03-03T11:54:58.063 に答える