XQuery get value from node root without child nodes

  • hi guys,

    Still trying to get my head around Xquery

    I have the following logic

    SET @CRM = (

    SELECT TOP 1 CRM FROM

    (

    SELECT

    cast(xmltext.query('/PARAMS/FILTERS/CRM')as nvarchar(max)) as 'CRM'

    FROM

    #XML

    ) X

    )

    Which returns me the following result

    <CRM>ONLY<TYPE>FSACLOSED</TYPE><TYPE>NRCLOSED</TYPE></CRM>

    I would like to get hold of just the 'ONLY' part of this string, i.e. only the value under the root of the node, not the child nodes or their values.

    Can I do this with XQuery or do I need to use string manipulation to isolate it?

  • Change

    xmltext.query('/PARAMS/FILTERS/CRM')

    to

    xmltext.query('/PARAMS/FILTERS/CRM/text()')

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply