I currently have several rows (say around 100 for args sake) in a table, and within that table I have an XML field which contains data as follows (example):
<cf1>summer</cf1>
.. I might then have another row or rows containing:
<cf1>winter</cf1>
.. and for completeness, another few rows perhaps containing multiples of:
<cf开发者_C百科1>spring</cf1>
So my question is:
How to write a query/proc to return me a unique resultset of all possible xml nodes in my xml field?
I guess I can return say 100 rows, and then using C# to filter that down.. but I am guessing that with SQL 2008 there are far better ways of doing that!
The idea is that you use XQuery to grab the data in a subquery and just treat it as another row in the table. Like such:
SELECT DISTINCT Season
FROM
(SELECT CAST(Xml_Field.query('data(/cf1)') AS VARCHAR) AS Season
FROM My_Xml_Table)
This query will return:
Season
------
summer
winter
spring
精彩评论