How to Copy data from XML Column and Insert it into a Table which Contains column names same as XML Tag Names in MS SQL SERVER -


say if have table contains single column of xml datype eg:

    details(column name in table)     <emp>--row1 in column       <name>alice</name>       <id>1</id>     </emp>     <emp>--row2 in column       <name>bob</name>       <id>2</id>     </emp> 

now need read column table , insert on table contains same column names xml tag names i.e

    emp     name            id     alice           1     bob             2 

i have tried openxml ,xquery etc . nothing seems work read column column , insert row . can please guide me on this?

i think can this.

declare @str_xml xml --- xml data column table   select     [table].[column].value('name[1]', 'varchar(100)') ' name ',     [table].[column].value('id[1]', 'varchar(20)') ' id ' @str_xml.nodes('/ emp') [table]([column])  note : name[1] = name on must same tag <name> not <name> 

when can make output table xml string can use insert table.

http://programcall.com/11/dotnet/how-to-read-data-from-xml-string--and-insert-to-table-sql-server.aspx


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -