Trigger Problem

  • I've created a trigger on a table.  The trigger syntax appears to be correct but doesn't seem to be firing.  Can anyone help with suggestions?  Here is the trigger syntax:

    CREATE TRIGGER AddSiteName

    ON pmronline.test

    for INSERT

    AS

    update test

    set qsite = case 

     when c.field_value = 'conc' then 1

     when c.field_value = 'ext' then 2

     when c.field_value =  'irv' then 3

     when c.field_value = 'jack' then 4

     when c.field_value = 'phix' then 5

    end

    from  INSERTED a, pdc_demo_info c

    where a.QID_1 = c.panel_id

    and  c.field_name = 'Site_name'

  • You're updating a table called 'test' - but you're not referencing 'test' in the FROM clause, so the update is not correlated to anything in inserted or pdc_demo_info.

    What exactly are you trying to do ?

     

  • customers are taking a survey and after they've completed the survey the record is inserted into the "test" table - at that point I want my trigger to fire and update another field in the "TEST" table based on the data from pdc_demo_info table.  I had actually tried using the table name "test" in the FROM clause before using "Inserted" and it still didn't work.

  • >>I had actually tried using the table name "test" in the FROM clause before using "Inserted" and it still didn't work.

    You absolutely must join test to inserted, otherwise you'll update the wrong rows in test. Can't help any further without DDL/Primary Key details on table 'test'.

     

  • Could the problem be that I've created two separate insert triggers on the same table?

  • Unless you fix *this* trigger to correctly join, you're going to have problems regardless of other triggers.

     

     

Viewing 6 posts - 1 through 5 (of 5 total)

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