0
<storage xmlns="http://energy" created-on="2013-01-21T05:00:15Z">
<country>Italy</country>
<Points>
    <point>Callato;Cellino</point>
</Points>
    </storage>

上面的数据是表中的一列(xmlcolumn),需要从上面单独检索创建的。当我使用下面的查询时,我得到了 null

 SELECT
 OutputXML.value('(storage/@created-on)[1]','date') 
  AS ProductType,*
FROM [DataOutput];

我在做什么错误,谢谢阿伦

4

1 回答 1

0

您需要为查询指定命名空间:

declare @t table (a xml)
insert into @t(a) values ('<storage xmlns="http://energy" created-on="2013-01-21T05:00:15Z">
<country>Italy</country>
<Points>
    <point>Callato;Cellino</point>
</Points>
    </storage>')

 SELECT
 a.value('declare namespace x = "http://energy";
          (x:storage/@created-on)[1]','date') 
  AS ProductType,*
FROM @t;

为了便于阅读,我将其分成两行。然而,没有必要这样做。

结果:

ProductType a
----------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2013-01-21  <storage xmlns="http://energy" created-on="2013-01-21T05:00:15Z"><country>Italy</country><Points><point>Callato;Cellino</point></Points></storage>
于 2013-01-21T07:47:38.820 回答