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
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, May 14, 2015 10:03 AM
Points: 504, Visits: 766
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: Today @ 3:18 PM
Points: 1,817, Visits: 21,294
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



Post #1392345
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse