I have temp table #xml that have 2 columns:
CREATE TABLE #xml
(
id int,
xmlroutes xml
)
INSERT INTO #xml (id, xmlroutes)
(SELECT TOP 50 Id, CAST(RouteParameters as xml) as xmlroutes FROM LoggingRecords WHERE RouteParameters IS NOT NULL)
I have selected id and pair xml with next script:
(SELECT id, T2.Loc.query('.') as pair
FROM #xml
CROSS APPLY xmlroutes.nodes('/route/pair') as T2(Loc))
LoggingRecords contains string (nvarchar) that castable to xml.
I have next xml structure of all records:
<route>
<pair key="x" value="y"/>
<pair key="z" value="1"/>
<pair key="a" value="b"/>
</route>
I want to select next data from each record of #xml table (each id can relate with many pairs):
- Id
- key
- value
How can I do this?
SE-Data