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.
| Author |
Topic |
|
dhanlak
Starting Member
5 Posts |
Posted - 2011-10-04 : 11:27:04
|
| hi,I need to copy tableA and tableB from database1 to database2. Both table has the same structure. Only PlanID 1 and PlanID 2's values should be copiedtableA is copied, but tableB is a bit confusing.DATABASE1tableA ItemID | PlanID | col3 | col4 | col5 ......------ | -------|------|------|----------21 | 122 | 123 | 124 | 125 | 126 | 227 | 228 | 229 | 330 | 3tableBID | ItemID | col3 | col4 | col5 ......-- | -------|------|------|-----------11 | 2112 | 2113 | 2214 | 2215 | 2316 | 23DATABASE2This is how it should be copiedtableA ItemID | PlanID | col3 | col4 | col5 ......------ | -------|------|------|----------1 | 1002 | 1003 | 1004 | 1005 | 1006 | 2007 | 2008 | 200tableBID | ItemID | col3 | col4 | col5 ......-- | -------|------|------|-----------1 | 12 | 13 | 24 | 25 | 36 | 3ItemID -> identity key for tableAID -> identity key for tableBItemID -> is foreign key in tableBPlanID -> identity key for Plan table, which i have not given here.Also, after copying from db1 to db2, other columns(col3,col4....) for tableB in db2 should be same(only the identity field values may be different) as the columns for tableB in db1Similarly, other columns(col3,col4....) for tableA in db2 should be same(only the identity field values may be different) as the columns for tableA in db1Is there any way to achieve this using a single Query?i tried this, but, how to get the ItemID value from tableAselect @ItemID = ?, col3,col4....from ..db1.tableBinto ...db2.tableBleft join ???where PlanID in (1,2)Please does anyone know how to solve this? Thanks in advance |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-04 : 11:40:40
|
| didnt get how all PlanID values became 100 in tableA DATABASE2. Can you explain?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|