dbTalk Databases Forums  

Copy data from one table Column another table Xml Node

microsoft.public.sqlserver.xml microsoft.public.sqlserver.xml


Discuss Copy data from one table Column another table Xml Node in the microsoft.public.sqlserver.xml forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mukesh
 
Posts: n/a

Default Copy data from one table Column another table Xml Node - 03-19-2010 , 06:49 AM






I have two tables like this

declare @Habits_new table(ID int,Habits xml default '<habits></habits>')
declare @Habits_OLD table (ID varchar(50), Habit varchar(50))


Having data Like this

INSERT @Habits_new values(1,'<habits><habit>Drink</habit></habits>')
INSERT @Habits_new values(2,'<habits><habit>snor</habit></habits>')
INSERT @Habits_new values(3,'<habits><habit>walk</habit></habits>')
INSERT @Habits_new
values(4,'<habits><habit>Eat</habit><habit>drink</habit><habit>work</habit><habit>enjoy</habit></habits>')

insert @Habits_OLD values(3, 'Cook')
insert @Habits_OLD values(4, 'Biking')
insert @Habits_OLD values(4, 'walk')

I want to move Data from _old table to _new table.

I tried this query


UPDATE A SET
habits.modify('insert <habit>{sql:column("B.Habit")}</habit>as last
into (/habits)[1] ')
FROM @Habits_new AS A JOIN @Habits_OLD AS B ON A.ID=B.ID


***But this query Insert Only one record for the id 4***

1 <habits><habit>Drink</habit></habits>
2 <habits><habit>snor</habit></habits>
3 <habits><habit>walk</habit><habit>Cook</habit></habits>

4 <habits><habit>Eat</habit><habit>drink</habit><habit>work</habit><habit>enjoy</habit><habit>biking</habit></habits>

Anybody help



Full Sql Query

declare @Habits_new table(ID int,Habits xml default
'<habits></habits>')
declare @Habits_OLD table (ID varchar(50), Habit varchar(50))

INSERT @Habits_new values(1,'<habits><habit>Drink</habit></habits>')
INSERT @Habits_new values(2,'<habits><habit>snor</habit></habits>')
INSERT @Habits_new values(3,'<habits><habit>walk</habit></habits>')
INSERT @Habits_new
values(4,'<habits><habit>Eat</habit><habit>drink</habit><habit>work</habit><habit>enjoy</habit></habits>')

insert @Habits_OLD values(3, 'Cook')
insert @Habits_OLD values(4, 'biking')
insert @Habits_OLD values(4, 'snor')



select * from @Habits_new
select * from @Habits_OLD

UPDATE A SET
habits.modify('insert <habit>{sql:column("B.Habit")}</habit>as last
into (/habits)[1] ')
FROM @Habits_new AS A JOIN @Habits_OLD AS B ON A.ID=B.ID

SELECT * FROM @Habits_new

Reply With Quote
  #2  
Old   
bking
 
Posts: n/a

Default RE: Copy data from one table Column another table Xml Node - 05-12-2010 , 09:35 AM






Did you ever figure out a solution? I have the same problem and have had no
luck finding a way to get it to work.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.