Trigger isn't working

  • Hi,

    I have a trigger, that works fine elsewhere but is not working at this location. At one point I put a print statement in the trigger just to see if it was firing. The message comes through, but the data is not being copied to the new table.

    USE [db name]
    GO
    /****** Object: Trigger [dbo].[Front Temps] Script Date: 10/16/2026 12:46:42 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    ALTER TRIGGER [dbo].[Front Temps]
    ON [db name].[dbo].
    after INSERT
    AS
    Begin
    SET NOCOUNT ON;

    INSERT INTO [db name].dbo.AlarmQueFront (CarId, ImageTime, FrontAlarmStatus, FrontAlarmTemp, Direction, TVImage, Images)
    SELECTi.[Car ID],
    i.[Image Time],
    i.[Front Image Alarm Status],
    i.[Front High Temp],
    i.[Direction Label],
    dbo.[TorpedoVision Data Images].[Front Jpeg],
    i.[Images]
    FROM INSERTED as i
    INNER JOIN dbo.[db table name ]
    on dbo.[db table name].ID = i.Images

    WHERE i.[Front Image Alarm Status] <> '0';

    END

     

  • 2 qs:

    1. Shouldn't you be joining on the ID = ID and not on ID = images?
    2. Is it possible that [Front Image Alarm Status] can be NULL?  If so, the WHERE condition will not be true and any row(s) with NULL will not be INSERTed.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Hi,

    No, It is ID in one table and Images in the other. (That's how the programmers set it up.)

    There is always a [Front Alarm Status]

    1.  OK, but the "inserted" table in the trigger should be joining to the same table name as the trigger is fired on, right?, on the source table, not on the "AlarmQueFront" table, the target table.

    Sorry if this is wrong, but you didn't provide a consistent table name for the trigger, even if it's a dummy name, so it can be difficult for me to match up the table names properly.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • The way I understand it is the INSERTED table is the row of data that has just been added to the original table. it's temporary. The "images" column is the Id for the original table, this table contains data. I am joining the original table with another original table that contains images. I then am trying to get the data in the INSERTED table, which should be the columns from the two original tables into the dbo.AlarmQueFront table.

    Sorry about the dummy names for the tables my originals have company names in them. I should have made up better dummy names.

  • Try LEFT JOIN instead of INNER JOIN and see if anything goes through.

    You may want to use

    IF APP_NAME() = 'Microsoft SQL Server Management Studio'
    SELECT ....
    FROM inserted
    LEFT JOIN ... TV

    to see what's going on when you run the code in  test mode.

    _____________
    Code for TallyGenerator

  • The Left Join did bring over the data from the data table, but did not bring over the image for the image table.

  • I think the reason the image isn't moving over is because I am inserting fake data and have to use NEWID() for the ID field so the Images and ID aren't matching. I will try allowing actual data to populate and see what happens. Thank you for your help.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply