Link to home
Start Free TrialLog in
Avatar of Sh M
Sh MFlag for United States of America

asked on

SQL Query - sql 2005/2008 - data migration

Hi,

Having the following tables:

tableA
column: A_IDPK, ADesc, A_X,B_ID(FK)

tableB:
column: B_ID, BDesc

TableC
column: C_IDPK, BDesc, C_A_X, B_ID(FK),AutoIDoFA

TableA is already populated, table B is already populated.
I can use the source table to populate tableC.
The column A_X is unique identifier for table A, it also matches with C_A_X in tableC.
The source table already has a column matching C_A_X. so there is no problem to populate
this column when migrating data to tableA.
I like to write a query to update the value of C_X with  
what I need to do is to actually find the relevant A_IDPK of A_X and also put that number into tabeC.AutoIDoFA.

how can this be done.

Thanks in advance
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Try this:

UPDATE tableA,TableC SET TableC.AutoIDoFA=tableA.A_IDPK WHERE TableC.C_A_X=tableA.A_X;

That should match records between tableA and TableC, where A_X=C_A_X, and put the identity PK of table A into the AutoIDoFA field of TableC.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sh M

ASKER

Tanks