开发者

SQL Server XQuery not working with .nodes()

开发者 https://www.devze.com 2023-02-09 00:27 出处:网络
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\">

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

精彩评论

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