SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 CAST(EmpDetails as XML).query does what within sel
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

540 Posts

Posted - 11/26/2012 :  10:52:15  Show Profile  Reply with Quote
I have the follwing with in select query
What does it mean as XML and then using .query

What does it do, can someone please explain.

CAST(EmpDetails as XML).query('data(HR_Pay_class)') as PayClass

Thanks a lot for the helpful info.

cplusplus
Aged Yak Warrior

540 Posts

Posted - 11/26/2012 :  11:02:06  Show Profile  Reply with Quote
Understood, it is querying an XML datatype field's data. within that xml data querying particular element.

Thanks.
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/26/2012 :  11:05:03  Show Profile  Reply with Quote
SQL Server has a set of xquery functions (even though it is a rather limited subset of the W3C specifications) for querying, composing, and modifying XML data.

In the statement you posted, you are casting EmpDetails column (which probably is a character type) to an XML type, and then using the xquery function "query" to look for the xml node named "data(HR_Pay_class)".

There is a description of xquery functions in SQL Server here including some examples of the query function that is used in your example: http://msdn.microsoft.com/en-us/library/ms345122(v=sql.90).aspx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000