Trigger help

  • Hello every one. I created this trigger which works fine for it's purpose. The problem is that there are other Stored Procs that update the same table, now even if the user did not change the values in the record the SPs still perform an update (on all columns which cause my trigger to fire) I was thinking of modifying this trigger to fire only if the values have changed. Ultimately I want to modify the rest of the Stored Procs, but for now how can I modify only the trigger to perform this action? Thanks in advanced.

    ALTER      TRIGGER TR_PRECIO_HIST_UP

     ON TbNvLpPsMaestroGrl

     FOR UPDATE

     AS

     IF   UPDATE(Ps_PreBase)

                OR UPDATE(Ps_PreVta)

     OR UPDATE(Ps_Costo)

     OR UPDATE(Ps_PreSug)

     BEGIN

      INSERT INTO TbNvLpHisMaestro

      (

      PsHis_FecIni,

      PsHis_FecFin,

      PsHis_PreBase,

      PsHis_PreVta,

      PsHis_PreCosto,

      PsHis_FacVta,

      PsHis_PreSug,

      PsHis_Contrib,

      PsHis_FecAct,

      Ps_Id,

      Usr_Id,

      Mda_Cod,

      Cia_id

     &nbsp

      SELECT

      DELETED.Ps_FecIni,

      GETDATE(),

      DELETED.Ps_PreBase,

      DELETED.Ps_PreVta,

      DELETED.Ps_Costo,

      DELETED.Ps_FacVta,

      DELETED.Ps_PreSug,

      DELETED.Ps_Contrib,

      GETDATE(),

      DELETED.Ps_Id,

      DELETED.Usr_Id,

      DELETED.Mda_Cod,

      DELETED.Cia_id

      FROM DELETED

      END

      

        

  • This was removed by the editor as SPAM

  • IF EXISTS(

    SELECT *

    FROM DELETED D INNER JOIN INSERTED I

    ON D.PS_ID = I.PS_ID

    WHERE D.Ps_PreBase  <>  I.Ps_PreBase

    OR    D.Ps_Costo  <>  I.Ps_Costo

    OR    D.Ps_PreVta  <>  I.Ps_PreVta

    OR    D.Ps_PreSug  <>  I.Ps_PreSug

    )

    BEGIN

    BEGIN TRANSACTION

      INSERT INTO TbNvLpHisMaestro

     

    I answered it myself

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

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