On 2016/03/03 2:55 AM, Sam Carleton wrote:
> 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;

Does this trigger not compute, is not accepted, or does not work once 
installed? What is the problem exactly?

 From a cursory glance, I can tell you that the this line:

"    SELECT f1.FolderId, f1.ImageId, (SELECT MIN(f2.instertedon) FROM"

messes with my OCD, which might be a clue - did you mean to spell 
"Inserted On" like "f2.instertedon"?

Cheers,
Ryan

Reply via email to