从xml变量sql获取值

时间:2014-03-09 15:17:10

标签: sql xml xsd sqlxml

您好我正在使用SQL并在变量

中具有以下值
<needs xsi:noNamespaceSchemaLocation="../../../../docs/xsd/rx/i2.0/needs-i2.0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Method qid="String" isApplicable="true" location="needs"
        source="needs">
        <Yes>false</Yes>
        <No>true</No>
    </Method>
    <S_Needs qid="String" isApplicable="true" location="needs"
        source="needs">
        <N_Value type="String" id="String" from="String"> NEED THIS VALUE </N_Value>
    </S_Needs>
    <Testing qid="String" isApplicable="true" location="needs"
        source="needs">
        <Yes>false</Yes>
        <No>false</No>
        <Defaults>true</Defaults>
    </Testing>
</needs>

路线是需要,S_Needs,N_Value我需要N_Value我怎样才能得到这个值

1 个答案:

答案 0 :(得分:1)

select @XML.value('(/needs/S_Needs/N_Value/text())[1]', 'nvarchar(max)')

SQL Fiddle