Solved

Update records in 1 table with results from another

Posted on 2014-11-21
5
153 Views
Last Modified: 2014-11-21
I may not have explained what I am looking for well in the the title, but this is what I am trying to accomplish.

I have results from 1 query (see below), and I want to update all of the records in TableB that have the same ID as the results from the select statement. For example, if the query returns 3 IDs, I want to take those and update the records in TableB based on those IDs. (Update TableB... set somevalue='blah'... etc.

I know this can be done a few different ways in coldfusion or even just using the SQL. I just need a rough example.

Thanks for any help you can offer

SELECT     TableA.TheID, TableB.AValue, TableA.AUser, 
                      TableB.TheID
FROM         TableA INNER JOIN
TableB ON TableA.TheID = TableB.TheID

Open in new window

0
Comment
Question by:earwig75
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40457602
UPDATE TableB
SET TableB.AValue = TableA.AUser
FROM         TableA
INNER JOIN TableB ON TableA.TheID = TableB.TheID
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40457607
I would suggest testing it by surrounding it by:

BEGIN TRAN
Select * from TableB
<<Insert Code>>
Select * from TableB
ROLLBACK TRAN

This way you can test if the update has worked without committing the transaction.
0
 

Author Comment

by:earwig75
ID: 40457625
Thank you, I may not have explained myself. I don't want to set items to be equal between the tables.

If my select statement returns IDs: 5,7 and 9, I want to update the records in tableB where the ID is 5,7 and 9...

Something like this:

Update TableB
Set Status="Open", Color="Green"
Where TheID......(this is where i want to use the IDs from the select)

Thank you.
0
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40457635
Roughly the same thing.

UPDATE TableB
SET TableB.Status="Open", TableB.Color="Green"
FROM         TableA
INNER JOIN TableB ON TableA.TheID = TableB.TheID
0
 

Author Closing Comment

by:earwig75
ID: 40457659
Awesome, that's what I was looking for. Thank you.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now