I want to use CASE and see whether the columns = total then update a table with todays date.
UPDATE dbo.Audit
SET AUD_CloseDate =
CASE
WHEN Scored + NA = Total THEN GETDATE()
At the end I want to see if col1 + col2 = col3, if so then update my column to todays date, and if there is a date already then do nothing.
Scored + NA = Total <---- they are from a temp table
You were almost ready:
UPDATE dbo.Audit
SET AUD_CloseDate = CASE
WHEN Scored + NA = Total THEN GETDATE()
END
WHERE AUD_CloseDate IS NULL
you need not run the update on all the rows, just filter on the ones where you want to update:
update dbo.audit
set aud_closedate = getdate()
where scored + na = total
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.