Solved

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

Posted on 2009-03-30
3
536 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 300 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 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

737 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