• sqlnaive (5/23/2013)


    Why not try three different triggers rather than using one ?

    If you insist on making just one trigger based on all events, here is what you can do inside the trigger:

    IF EXISTS(SELECT * FROM inserted) AND EXISTS(SELECT * FROM deleted)

    BEGIN

    EXEC PROC_FOR_UPDATE

    END

    IF EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted)

    BEGIN

    EXEC PROC_FOR_INSERT

    END

    IF NOT EXISTS(SELECT * FROM inserted) AND EXISTS(SELECT * FROM deleted)

    BEGIN

    EXEC PROC_FOR_DELETE

    END

    Insert Happens mince do you mean by AFTER INSERT OR INSTEAD OF INSERT, if it is after insert you can create three seprate triggers or suggsted in previous post or use output parameter as I described , If it is INSTEAD OF INSERT the mail insert will not fire in its place you can update other table as required.