I'm trying to work with some xml data we have in our database.
The starting point is a table with this rough outline:
CREATE TABLE MyTable
(
ID INT NOT NULL IDENTITY(1,1),
...,
FKSiteID INT NOT NULL REFERENCES ...,
...,
Keywords XML(DOCUMENT info.Keywords) NULL
)
a typical xml snippet could be:
<keywords xmlns="http://www.educations.com/Info/Keywords">
<keyword>keyword 1</keyword>
<keyword>keyword 2</keyword>
<keyword>keyword 3</keyword>
<keyword>keyword 4</keyword>
<keyword>keyword 5</keyword>
</keywords>
what I want to achieve at the end is a view showing all the keywords grouped in a single xml document following the same schema by the value of FKSiteID.
As a middle step I was trying to extract all the keywords but I didn't manage to do it without using a table function and CROSS APPLY to it the table.
Any other hint?
CROSS APPLY.....