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
 Import/Export (DTS) and Replication (2000)
 Moving multiple rows from one table to another

Author  Topic 

sspydy43
Starting Member

1 Post

Posted - 2006-07-05 : 17:19:39
Sorry if this is in the wrong forum, SQL is pretty new to me and I hope someone can help me with this question.

I have two tables table_a and table_b. table_a has the FK app_id and table_b has the PK app_id. Table_b also has a populated field called app_name, and table_a has a newly created field called app_name with no data in it. What I need to do is create an insert statement that will look at the app_id(s) in table_b and match it/them to a app_name in table_b. I then want to take that app_name and insert it into table_a in the same row as the associated app_id.

Does anyone have a script to do something like this, or can someone explain the best way to do this? Thanks for any help in advance and sorry if this does not make sense.

PSamsig
Constraint Violating Yak Guru

384 Posts

Posted - 2006-07-06 : 01:41:30
UPDATE a SET app_name = b.app_name
FROM table_a a
INNER JOIN table_b b
ON b.app_id = a.app_id

-- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2006-07-06 : 04:28:54
Just a friendly word of advice - make sure you have a good backup prior to doing something like this...


-ec
Go to Top of Page
   

- Advertisement -