Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL UPDATE help -- 1

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
0
0
US
I have two tables --
mhrsDemo, and demo --
They have records in them that sometimes equal each other (talking PK). When they do equal each other, I want to take some values from mhrsDemo and UPDATE them to the demo table

I'm trying to consolidate two demographic tables into one --

Here is my erroneous statement:

UPDATE demo
SET demo.region2 = mhrsDemo.region, demo.mhrs = mhrsDemo.mhrs
FROM
(SELECT mhrsDemo.[id], mhrsDemo.region, mhrsDemo.mhrs FROM selectDemo INNER JOIN
mhrsDemo ON selectDemo.id = mhrsDemo.ID)


See, so all I really want is two fields from the mhrsDemo table to be updated to existing records in the demo table where the PK (id in both) are equal to each other. I have THOROUGHLY confused myself here, and would appreciate some help.

If you need more info, just ask -- I'm not quite sure what all you will need --

Thanks everyone :)
Paul Prewett
 
Let me rephrase the question --

Can someone please post an example of some syntax on how I could go about updating a field in one table based on the values of a field in another table...

I think I could take it from there if you could provide me with that... In reading my post up there, I think it was a bit too vague.

thx
Paul Prewett
 
You're not far off. I believe the syntax you need is:

UPDATE demo
SET demo.region2 = mhrsDemo.region, demo.mhrs = mhrsDemo.mhrs
FROM Demo JOIN mhrsDEMO ON Demo.Id = mhrsDemo.Id

 
Oh so close... (me, that is... you were right on)

Thanks, ScottAW. :)
 
UPDATE DEMO
SET demo.region2 = mhrsdemo.region,
demo.mhrs = mhrsdemo.mhrs
FROM demo LEFT OUTER JOIN
MHRSDEMO ON DEMO.ID = MHRSDEMO.ID


?? br
Gerard
(-:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top