TR_CONSTITUENT_TASYNC_D

Definition

Copy


    CREATE trigger TR_CONSTITUENT_TASYNC_D on dbo.CONSTITUENT after delete not for replication
    as begin
      if dbo.UFN_B2T_CONTEXTISSYNC() = 1
      begin
        delete from dbo.TA_CONSTITUENT
        where ID in(select ID from DELETED)

        delete from dbo.TA_ACCOUNTS
        where ID in(select ID from DELETED)

        delete from dbo.TA_NAMES0
        where ID in(select ID from DELETED)

        delete from dbo.B2TROWS
        where BBECID in(select ID from DELETED)
        and TATABLE in('ACCOUNTS','NAMES')
      end
      else
      begin
        merge dbo.TA_CONSTITUENT t
        using (select ID from DELETED) d
        on (d.ID = t.ID)
        when matched and t.ACTIONCODE = 1 then
          delete
        when matched then
          update set ACTIONCODE = 3;

        merge dbo.TA_ACCOUNTS t
        using (select ID from DELETED) d
        on (d.ID = t.ID)
        when matched and t.ACTIONCODE = 1 then
          delete
        when matched then
          update set ACTIONCODE = 3;

        merge dbo.TA_NAMES0 t
        using (select ID from DELETED) d
        on (d.ID = t.ID)
        when matched and t.ACTIONCODE = 1 then
          delete
        when matched then
          update set ACTIONCODE = 3;

        delete from dbo.TA_NEWCONSTITUENT
        where ID in(select ID from DELETED);
      end
    end