?
Solved

MSSQL 2000 Update column (multiple records) based on select from another table

Posted on 2009-03-30
3
Medium Priority
?
542 Views
Last Modified: 2013-11-15
Ok as dumb as this might sound, I forgot how to update multiple records in a single table based on a select from another table.

For example I have a table I backed up and made changes to a live table and therefor they are the same structure and lets say I made a mistake and would like to revert back the changed data prior (assuming I did not do a begin tran), I would like perform an update and compare the id number to be the same in the live table as the backed up table. I know this code I am writing below is not a working peice of work but it was something i thought in my head to get started with.


UPDATE mytable
SET mycol = (select mycol from myothertable where active = 'y' and currentrevision = 'y')
where mytable.myid = myothertable.myid

Open in new window

0
Comment
Question by:smyers051972
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 1200 total points
ID: 24020668
You can do it two ways:

UPDATE mytable
SET mycol = (select mycol from myothertable where active = 'y' and currentrevision = 'y' and mytable.myid = myothertable.myid)

or

UPDATE mt
SET mycol = mot.mycol
from mytable mt
join myothertable mot
on mytable.myid = myothertable.myid
where mot.active = 'y'
and mot.currentrevision = 'y'
0
 
LVL 15

Assisted Solution

by:MNelson831
MNelson831 earned 800 total points
ID: 24020673
Update MyTable
Set MyField = OtherTable.MyField
From MyTable inner join OtherTable on MyTable.UniqueID = OtherTable.UniqueID
0
 
LVL 1

Author Closing Comment

by:smyers051972
ID: 31564413
Thanks!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question