sql server - Project relational data to XML column - is it possible? -


i have 2 tables of following structure:

people  id | lastname | firstname | other columns... 

the second table has xml column:

id | myxmlcol | other columns... 

myxmlcol stores following xml:

<mydata>   <block>     <person id="1" />     ...other nodes   </block>   ...other blocks </mydata> 

the id attribute points id column of people table.

what need, query myxmlcol, returns:

<mydata>   <block>     <person id="1" lastname="jones" firstname="bob" />     ...other nodes   </block>   ...other blocks </mydata> 

is possible make such projection? i'm using sql server 2012.

if there can 1 element "person" in single element "block", should suit:

update t set myxmlcol.modify('     insert (         attribute lastname {sql:column("p.lastname")},         attribute firstname {sql:column("p.firstname")}     )     (/mydata/block/person)[1]') @table2 t inner join @people p on t.myxmlcol.value('(/mydata/block/person/@id)[1]', 'int') = p.id 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -