Update Trigger that ignores NULL value updates in the source cloumn

  • I have two tables: Table1 and Table2

    What I want to do is create a trigger that, when col1 on Table1 is updated it automatically updates col1 on Table2. However should col1 on Table1 be updated to NULL I wish is to be ignored i.e. any NULL value updates on TABLE1.COL1 should be ignored.

    I thought the following would work but it doesn't

    CREATE TRIGGER [UPDATE] ON [dbo].[TABLE1]

    FOR INSERT, UPDATE, DELETE

    AS

    UPDATE Table2

    SET[COL1] =

    (SELECT [COL1]

    FROM table1

    WHERE table1.[1] IS NOT NULL

    AND table1.ID =table2.id)

    Any ideas where I am going wrong?

  • UPDATE  t2

               SET[COL1] = i.[1]

    From Table2 t2 join  inserted i

         on  i.ID = t2.id

    where i.[1] IS NOT NULL

     


    * Noel

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

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