How about this:
SELECT Year, EPvalue('(ID)[1]', 'INT') AS 'ID', EPvalue('(Name)[1]', 'VARCHAR(50)') AS 'Name', EPvalue('(LastName)[1]', 'VARCHAR(50)') AS 'LastName' FROM dbo.YourTable CROSS APPLY Fields.nodes('/Employees/Person') AS E(P)
You basically select Year
from the base table and then retrieve each <Person>
node from the Fields
column into an "embedded XML table" called E
with one XML column called P
(you can choose any names you like) that you again Query and retrieve from individual items.
marc_s
source share