Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

XQuery get value from node root without child nodes Expand / Collapse
Author
Message
Posted Tuesday, December 4, 2012 3:42 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 10:34 AM
Points: 386, Visits: 624
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?

Post #1392332
Posted Tuesday, December 4, 2012 4:01 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 8, 2014 6:13 AM
Points: 1,694, Visits: 19,550
Change

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

to

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


____________________________________________________

How to get the best help on a forum

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

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1392345
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse