Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to copy the data from one table to another

Author  Topic 

Nazri
Starting Member

8 Posts

Posted - 2005-10-20 : 07:34:05
hi
i have some problem...how to copy the data from one table to another
for example
table:xxx

id name address parentid
1 xxx Delhi null
2 yyy mumbai 1
3 zzz Banglore 2

now i want to copy the data from xxx table to yyy..all things will be same onle change will be in column1 and column3(column1 will not be same to xxx table) like this

table:yyy

id name address parentid
4 xxx delhi null
5 yyy mumbai 4
6 zzz Banglore 5


with regards
Nazri

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-20 : 07:55:26
If id field of yyy table is idenetity then

Insert into yyy(name,address) Select name, address from xxx

Then reset your id to max id of xxx + 1 at yyy and run this update query

Update yyy set parentid=id-1

Refer point 1 here also
http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Nazri
Starting Member

8 Posts

Posted - 2005-10-20 : 08:02:15
hi madhivanan

actually there is parent child relation between id and parentid and in id i am inserting newid..and i want do through stored procedure.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-20 : 09:02:04
Did you try the method I suggested?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -