TR_CONSTITUENTSOLICITCODE_TASYNC_I

Definition

Copy


    CREATE trigger TR_CONSTITUENTSOLICITCODE_TASYNC_I on dbo.CONSTITUENTSOLICITCODE after insert not for replication
    as begin
      if dbo.UFN_B2T_CONTEXTISSYNC() = 0
      begin
        insert into dbo.TA_CONSTITUENTSOLICITCODE (ID, SYNCID, ACTIONCODE)
        select ID, newid(), 1
        from INSERTED
        -- don't sync records for groups

        where not exists(select 'x'
                         from dbo.GROUPDATA d
                         where d.ID = INSERTED.CONSTITUENTID
                         and d.GROUPTYPECODE = 1);

        -- note that the above insert could fail if row is deleted and then reinserted w/ same ID before sync is run

        -- since we would not know anything about whether the row is really the same or not, we need to throw an exception

        -- to resolve, run the sync, then retry the insert

      end
    end