SQLTeam.com | Weblogs | Forums

Moving data form one column to a seperate table column

I accidentally deleted a column out of a table in my production DB. (I know slap me for doing that) I now need to rebuild that.

I have a Backup DB from older data that I can use to insert the data into the production table.

Both tables are schemed the exact same way. I need column LINEHAUL_PAID copied to LINEHAUL_PAID in production table.

I need to move data from the old table/column and repopulate the current table/column... catch is it has to match with a LOADNUMBER. So I am unsure how to properly insert into with a proper where clause where the LOADNUMBERs match. There have been records added since the original backup was made and don't want to lose that info.

I'm sure this is a simple thing, but being I am writing into the production DB I need to be absolutely certain not to screw this up anymore.

UPDATE prod_table
SET LINEHAUL_PAID = restored_table.LOADNUMBER
FROM dbo.your_table_name prod_table
INNER JOIN restored_db.dbo.your_table_name restored_table ON 
    restored_table.LOADNUMBER = prod_table.LOADNUMBER

This worked fine with one error on your part... LOL

you had

Blockquote ```
SET LINEHAUL_PAID = restored_table.LOADNUMBER

and the correct syntax should be:

> Blockquote ```
SET LINEHAUL_PAID = restored_table.LINEHAUL_PAID

Other than that - all GOOD!!! Thanks a ton for the help.

OOPS, you're right, my typo there.

All good. Glad I caught that. I stared at that for like 10 minutes going something ain't right here!! LOL