Re: How to select an attribute value from an XML-column using XPath/XQuery?

Tech-Archive recommends: Speed Up your PC by fixing your registry



Robert Pettersson wrote:


I think that I should be able to do that by running this query:

Select
Parameters.value('/Parameters/Parameter[@Name="@SystemUserID"]/@Value', 'int') As SystemUserIDValue
From
MyTable

But all I get is this error message:

Msg 2389, Level 16, State 1, Line 6
XQuery [MyDB.dbo.MyTable.Parameters.value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'

Make sure the XPath selects a single node by using e.g.
(/Parameters/Parameter[@Name="@SystemUserID"]/@Value)[1]




--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
.



Relevant Pages

  • Re: new to xQuery -- problem
    ... You are running into a static typing error. ... I am new to XQuery and also to SQL 2005. ... tutorials on how to select xml nodes out of the database and i have run ... 'order by' requires a singleton (or ...
    (microsoft.public.sqlserver.xml)
  • new to xQuery -- problem
    ... I am new to XQuery and also to SQL 2005. ... tutorials on how to select xml nodes out of the database and i have run ... 'order by' requires a singleton (or ...
    (microsoft.public.sqlserver.xml)