Say I've got the following fields that make up a unique key in my table: (productid varchar(30), dateset date, dateend date)
I intend for dateend to be null until another row with the same productid with a newer dateset has been inserted, like this:
+----------+-------------+-------------+
|productid | dateset | dateend |
+----------+-------------+-------------+
|'PRODUCTA'|'2014-10-09' | NULL |
+----------+-------------+-------------+
|'PRODUCTA'|'2009-08-06' |'2014-10-09' |
+----------+-------------+-------------+
Now, I'm thinking about how I'd safely do this and I figure I'd run a trigger before the new row is inserted. It would essentially find the current max(dateset) where productid = @productid, and if it exists, it will update this row's dateend with @newdateset, the date that our new, succeeding row is inserted. The problem is, I have no idea how to get the variable @productid, or @newdateset. Is there any way to get the information of a row that's now about to be inserted? If I wrote:
insert into products (productid, dateset) values ('DEMOA', '2014-10-10')
How would I get my trigger to say @productid = 'DEMOA', @newdateset = '2014-10-10'?
Thanks,
Zakiir