您需要为查询指定命名空间:
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>