mateogp
asked on
How do you update a joined table in SQL SERVER?
Hi all,
I been trying for days to figure this one out and can't seem to get the task done.
I have two tables in SQL SERVER 2005. Table 1 is tblRecords and table 2 is tblRecords_appts and I need to join them to get be able to update the right records.
I need to update all records that have wedding dates that have passed and set canceled to yes.
So I figured the correct update statement would be:
I'm pretty sure it has to be an additional select under where. Any help would be appreciated!
Thanks,
Matt
I been trying for days to figure this one out and can't seem to get the task done.
I have two tables in SQL SERVER 2005. Table 1 is tblRecords and table 2 is tblRecords_appts and I need to join them to get be able to update the right records.
I need to update all records that have wedding dates that have passed and set canceled to yes.
So I figured the correct update statement would be:
UPDATE tblRecords_appts INNER JOIN
tblRecords ON tblRecords_appts.rid = tblRecords.rid
SET tblRecords_appts.cancelled = 'Y'
WHERE (tblRecords.weddate < '10/1/2013') AND (tblRecords_appts.locationid = '17') AND (tblRecords_appts.cancelled = 'N')
but obviously that is not working :(I'm pretty sure it has to be an additional select under where. Any help would be appreciated!
Thanks,
Matt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This was exactly what I needed to complete the task! Thanks so much!
Too bad I didn't post exactly the same thing LoL
ASKER
Sorry BriCrowe. I tried you're solution and added on the where first and it didn't work. I just tried it again and it did work. I'd give split credit but I don't think I can revise that now.
It's really not a big deal...it was a momentary annoyance and was rather petty on my part...as long as mateogp got the answer need it's all good.
BriCrowe
BriCrowe
ASKER
I'm sorry about that either way. I did request attention just haven't received any response yet. Thanks for the help everyone!!
How is the point split going?
ASKER
Oops sorry Tony I thought this was all taken care of. I did the split!
This article contains an example of a joined update. Note that only one table gets updated at a time (UPDATE tablename SET field1 = value1 FROM tablename INNER JOIN table2name ON tablename.key1 = table2name.fkey1 WHERE table2name.field2 = value2). Need more? I can help. Also, here is a link to the Technet article on UPDATE: http://technet.microsoft.com/en-us/library/ms187326(v=SQL.105).aspx