I need to update value_check column in table_work as N based on below conditions
Update value_check as N
- if employee_id in table_work has no employee_manager_id record (either blank/null or no record at all) in employees_contact table when getdate is between contact_eff_dt and contact_end_dt (join using employee_id)
- if employee_id in table_work has a record in employees_contact table but employee_manager_id work_location_state is not NJ or NY or ME ..mgr_work_location table has employee_manager_id and work_location_state columns.
I am able to do it with 2 update statements bit is there a simple way to use only one update statement? Maybe using multiple where exists conditions?
Here are the 2 updates I use now:
UPDATE 1
Update work
set work.value_check = 'N'
From table_work work
Where wotk.value_check = 'Y'
And not exists (select employee_manager_id
from employees_contact contact
Where contact.employee_id = work.employee_id
And getdate() between contact.eff_dt and contact.end_dt)
UPDATE 2
Update work
set work.value_check = 'N'
From table_work work
Join employees_contact contact On contact.employee_id= work.employee_id
Join mgr_work_location mgr On mgr.mgr_id = contact.employee_manager_id
Where work.value_check = 'Y'
And getdate() between contact.eff_dt
and contact.end_dt And mgr.work_location_state not in ('NJ','NY,'ME')