开发者

SQL Server XQuery not working with .nodes()

Given the followng xml doc, stored in an xml column called OfficersXML:

<Officers xmlns="urn:reuterscompanycontent:officersdirectors03" Major="3" Minor="0" Revision="2" lang="en-US">
  <RepNo>0004N</RepNo>
  <CompanyName Type="Primary">Alpharma Inc.</CompanyName>
</Officers>

Why doe开发者_开发百科s the following return 0 rows?

SELECT tbl.col.value(N'(./CompanyName)[1]',N'nvarchar(4000)') 
FROM dbo.RawData rd
CROSS APPLY OfficersXML.nodes(N'/Officers') tbl(col)


Try

SELECT tbl.col.value(N'(*:CompanyName)[1]',N'nvarchar(4000)') 
FROM dbo.RawData rd
CROSS APPLY OfficersXML.nodes(N'/*:Officers') tbl(col)

You can also use the with namespace set to a default namespace: WITH XMLNAMESPACES (DEFAULT 'urn:reuterscompanycontent:officersdirectors03')

More Info: http://msdn.microsoft.com/en-us/library/ms177607.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜