Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Handling xml data and formatting into separate table

$
0
0
I have xml data in table, here xml data looks mentioned below,And it’s taken from different table for each row[b][i]TableA[/i][/b]Tab_id xml_data1 xml_data1 -- eg: Table 12 xml_data2 -- eg: Table 2[b]xml_data1 [/b]<row> <col0> EMP_ID </col0> --COLUMN NAMES FOR DATA <col1> EMP_NAME </col1> --COLUMN NAMES FOR DATA <col2> EMP_COUNTRY </col2> --COLUMN NAMES FOR DATA</row><row> <col0> 1001 </col0> <col1> AAA </col1> <col2> USA </col2></row><row> <col0> 1002 </col0> <col1> BBB </col1> <col2> CANADA </col2></row>[b]xml_data2[/b]<row> <col1> HR_ID </col1> --COLUMN NAMES FOR DATA <col2> HR_NAME </col2> --COLUMN NAMES FOR DATA <col3> HR_ADDRESS </col3> --COLUMN NAMES FOR DATA <col4> HR_CITY </col4> --COLUMN NAMES FOR DATA</row><row> <col1> 100 </col1> <col2> GATES </col2> <col3> MS </col3> <col4> WASHINGTON </col4></row><row> <col1> 101 </col1> <col2> MALLA </col2> <col3> KF </col3> <col4> NEWYORK </col4></row>Actual table View of [b]xml_data1[/b] will be EMP_ID EMP_NAME EMP_COUNTRY1001 AAA USA1002 BBB CANADA Actual table View of [b]xml_data2[/b] will be HR_ID HR_NAME HR_ADDRESS HR_CITY100 GATES MS WASHINGTON101 MALLA KF NEWYORK [b]Here I need an output like [/b][i]Table name: TableA_Columns[/i]Tab_Id Column_Id Column_Name Position1 1111 EMP_ID 11 1112 EMP_NAME 21 1113 EMP_COUNTRY 32 2221 HR_ID 12 2222 HR_NAME 22 2223 HR_ADDRESS 32 2224 HR_CITY 4[i]Table name: TableA_Col_Values[/i]Tab_Id Column_Id Value_Id Value Row_No1 1111 1000001 1001 11 1112 1000002 AAA 11 1113 1000003 USA 11 1111 1000004 1002 21 1112 1000005 BBB 21 1113 1000006 CANADA 22 2221 1000007 100 12 2222 1000008 GATES 12 2223 1000009 MS 12 2224 1000010 WASHINGTON 12 2221 1000011 101 12 2222 1000012 MALLA 12 2223 1000013 KF 12 2224 1000014 NEWYORK 1Please comment if u need any clarification.Thanks a lot in Advance.

Viewing all articles
Browse latest Browse all 3145

Trending Articles