Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Aged Yak Warrior

567 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.

Aged Yak Warrior

567 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.

Go to Top of Page

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:
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000