XML Query within SQL Server

后端 未结 1 376
遥遥无期
遥遥无期 2021-01-13 09:07

I just starting to query XML within a SQL Server database. I am having trouble with the most basic query. Here is a simplified example. How do I return description? The S

相关标签:
1条回答
  • 2021-01-13 09:51

    Well, you're missing out on the XML namespace! :-)

    Try this:

    SELECT 
      Incidents.IncidentXML.query('declare namespace x="http://tempuri.org/dsIncident.xsd";
              (/x:dsIncident/x:IncidentInformation/x:Description)') AS Description 
    FROM Incidents
    

    The magic is the

    declare namespace x="http://tempuri.org/dsIncident.xsd"
    

    part here - it declares a namespace (with a prefix of your choice - can be anything - here 'x') for the period of the query on that XML data.

    Hopefully, that'll return something! ;-)

    Marc

    0 讨论(0)
提交回复
热议问题