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 2005 Forums
 Transact-SQL (2005)
 How to copy rows in a table joined to two other ta

Author  Topic 

jylland
Starting Member

27 Posts

Posted - 2009-12-14 : 18:06:49
How to copy rows and replace them in th same table joined to two other tables ?

I three tables

tableA, tableB and tableC,
tableA and tableB is joined Aid-idA and tableB and tableC is joined Bid-idB

I want to copy from TableC the Rows (Cid = 1, Name= Trek1, idB = 1 AND Cid = 2, Name= Trek2, idB = 1 AND Cid = 3, Name= Trek3, idB = 1) joined to tableB Row (Bid = 1, name = scene1, idA = 1)
and place them to the tableB Row (Bid =2, Name = Scen2, idA = 1)

How do I do this ?


TableA
Aid Name
1 scan1
2 scan2
3 scan3
4 scan4

TableB
Bid Name idA
1 scen1 1
2 scen2 1
3 scen1 2
4 scen1 3
5 scen1 4

TableC
Cid Name idB
1 Trek1 1
2 Trek2 1
3 Trek3 1
4 Trek1 2
5 Trek2 2
6 Trek1 3
7 Trek2 3
8 Trek1 4
9 Trek2 4
10 Trek1 5
11 Trek2 5

The result for table C after insert to tableC,

1 Trek1 1
2 Trek2 1
3 Trek3 1
4 Trek1 2
5 Trek2 2
6 Trek1 3
7 Trek2 3
8 Trek1 4
9 Trek2 4
10 Trek1 5
11 Trek2 5
12 Trek1 2
13 Trek2 2
14 Trek3 2

ddramireddy
Yak Posting Veteran

81 Posts

Posted - 2009-12-15 : 10:03:39
I replied to your question at this forum...
http://social.msdn.microsoft.com/Forums/en/transactsql/thread/5f148b4c-49a9-4822-93e9-6c880df4a633
Go to Top of Page
   

- Advertisement -