简体   繁体   中英

How to run this SQL update statement

I've read the documentation but for some reason it just isn't clicking. This is the update I want to run:

vSQL = "UPDATE consultant SET Availability = 'Available' FROM consultant JOIN contract ON consultant_id = contract_lead WHERE contract_end < sysdate ";

Any chance someone can give me the solution and explanation?

The use of sysdate implies (to me) that you are using Oracle. You probably want to set the availability to 'Available' to any consultant where the maximum end date is in the past. That would be:

UPDATE consultant c
    SET Availability = 'Available' 
    WHERE (SELECT COALESCE(MAX(co.contract_end), DATE '2000-01-01')
           FROM contract co
           WHERE c.consultant_id = co.contract_lead
          ) < sysdate;

EDIT (in response to the comment):

UPDATE consultant c
    SET Availability = 'Available' 
    WHERE (SELECT COALESCE(MAX(COALESCE(co.contract_end, sysdate)), DATE '2000-01-01')
           FROM contract co
           WHERE c.consultant_id = co.contract_lead
          ) < sysdate;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM