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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 CAST(EmpDetails as XML).query does what within sel

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2012-11-26 : 10:52:15
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

567 Posts

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

Thanks.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-26 : 11:05:03
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
   

- Advertisement -