I am working on a trigger that only needs to be fired when the value for
the column 'Selected' is 1.  How exactly do I write that trigger?  Here is
what I have come up with:

CREATE TRIGGER IF NOT EXISTS tu_Favorite_add_to_SlideShowImage AFTER UPDATE
    ON Favorite FOR EACH ROW *WHEN (NEW.Selected = 1)*
BEGIN
    INSERT INTO SlideShowImage (FolderId, ImageId, timeMarker)
    SELECT f1.FolderId, f1.ImageId, (SELECT MIN(f2.instertedon) FROM
Favorite f2 WHERE f2.FolderId = f1.FolderId AND f2.ImageId = f1.ImageId)
timeMarker
      FROM Favorite f1
        JOIN Customer c ON f1.CustomerId = c.CustomerId
        LEFT JOIN SlideShowImage ssi ON f1.FolderId = ssi.FolderId AND
f1.ImageId = ssi.ImageId
     WHERE f1.FolderId = NEW.FolderId AND f1.ImageId = NEW.ImageId
        AND f1.Selected = 1 AND c.IsInSlideShow = 1 AND f1.Status = 0 AND
ssi.rowid IS NULL;
    SELECT RAISE(IGNORE);
END;

Pax vobiscum,
Sam Carleton

Reply via email to