emplid week datecreated dateexpired
001 212 2018-03-19 2018-03-22 ---expire this record
001 212 2018-03-19 2018-03-19
001 212 2018-03-22
001 212 2018-03-22 2018-03-19
Microsoft SQL Server
Last Comment
Vitor Montalvão
8/22/2022 - Mon
Vitor Montalvão
Create an ON INSERT trigger where you'll update the record with an empty Expired Date. Example:
CREATE TRIGGER trg_ExpireDateON dbo.d_employeeAFTER INSERT AS UPDATE e SET e.dateexpired = GETDATE() FROM d_employee e INNER JOIN inserted i ON (e.emplid = i.emplid AND e.week = i.week AND e.datecreated = i.datecreated)GO
i just want to do update st-mt not trigger can you please help with that
Vitor Montalvão
Well, by your explanation is a trigger that you need.
If I misunderstood it, you already have the UPDATE statement in my trigger example. Just take and adapt it to your case.
this will not work if you look at source data dateexpiry is null for record 1 and 3 i just want to expire first record as new record now is 2018-03-22.
Open in new window