CREATE TABLE CurrentApplication ( StartDate datetime NOT NULL, EndDate datetime NOT NULL, NoOfDays integer, StaffID integer NOT NULL, AppStatus varchar(30) NOT NULL DEFAULT 'PENDING' )
CREATE TRIGGER InsertNoOfDays ON CurrentApplication AFTER INSERT BEGIN INSERT INTO CurrentApplication NoOfDays AS Datediff(day, StartDate, EndDate) END
I have NoOfDays column which should hold the DateDiff between StartDate and EndDate and the value should be inserted whenever a new record is inserted into the table. How do I write the trigger and do it? I've tried but my trigger doesn't work. Thanks!