T-sql data migration from xml to columns

ablack

New Member
I have temp table #xml that have 2 columns:\[code\]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)\[/code\]I have selected id and pair xml with next script:\[code\](SELECT id, T2.Loc.query('.') as pairFROM #xmlCROSS APPLY xmlroutes.nodes('/route/pair') as T2(Loc))\[/code\]LoggingRecords contains string (nvarchar) that castable to xml.I have next xml structure of all records:\[code\]<route> <pair key="x" value="http://stackoverflow.com/questions/11050014/y"/> <pair key="z" value="http://stackoverflow.com/questions/11050014/1"/> <pair key="a" value="http://stackoverflow.com/questions/11050014/b"/></route>\[/code\]I want to select next data from each record of #xml table (each id can relate with many pairs):[*]Id[*]key[*]valueHow can I do this?
 
Back
Top