Tech Off Post

Single Post Permalink

View Thread: EventArgs on Triggers?
  • User profile image
    NuTcAsE

    You could use the inserted table in your trigger to get the values that were inserted in the row.

    Example:

    Assuming you have a table with the following columns:
     ID[int], EmailAddress [varchar(2000)], EmailCount [int]

    The trigger:

    CREATE TRIGGER SampleTrigger
    ON MyTable
    AFTER INSERT
    AS

    DECLARE @ID int
    DECLARE @MessageCount int
    DECLARE @EmailAddress varchar(2000)

    SELECT
        @ID = ID,
        @EmailAddress = EmailAddress
    FROM
        inserted

    SELECT @MessageCount = COUNT ('C') FROM Messages WHERE EmailAddress = @EmailAddress

    IF (@MessageCount > 10)
    BEGIN
        -- Modify email and send message
    ELSE
    BEGIN
        -- Fallback do something else
    END