XML query() works, value() requires singleton found xdt:untypedAtomic

前端 未结 3 1652
轻奢々
轻奢々 2020-12-16 09:40

I have a typed xml document stored as text. So I use CONVERT the data type to xml by using a Common Table Expression in order to be able to use XML methods:

         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 10:31

    You need to use this:

    SELECT 
            x.requestpayload.value('declare namespace s="http://blah.ca/api";
                (/s:validate-student-request/s:student-id)[1]', 'int') 
        AS
            studentid
        FROM 
            xoutput x

    You need to put your XPath in ( ... ) and add a [1] to simply select the first value of that sequence.

提交回复
热议问题