Home Forums SQL Server 2008 T-SQL (SS2K8) XQuery: Get the value only, and not the child node values RE: XQuery: Get the value only, and not the child node values

  • DECLARE @xml XML =

    '<ROOT>

    <SPECIALNEEDS>

    INCLUDE

    <NEED>

    BLIND

    </NEED>

    <NEED>

    BRAILLE AUDIO

    </NEED>

    </SPECIALNEEDS>

    </ROOT>'

    SELECT TD.D.value('./text()[1]','Varchar(400)')

    FROM @xml.nodes('/ROOT/SPECIALNEEDS') AS TD(D)

    Please note the whitespace preserved on the left of INCLUDE, as it's part of the node text.

    You can LTRIM it or make sure you XML formed appropriately eg:

    '<ROOT>

    <SPECIALNEEDS>INCLUDE

    <NEED>

    BLIND

    </NEED>

    <NEED>

    BRAILLE AUDIO

    </NEED>

    </SPECIALNEEDS>

    </ROOT>'

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]