TR_RELATIONSHIP_TASYNC_I

Definition

Copy


        CREATE trigger TR_RELATIONSHIP_TASYNC_I on dbo.RELATIONSHIP after insert not for replication
        as begin
            if dbo.UFN_B2T_CONTEXTISSYNC() = 0
            begin
                insert into dbo.TA_RELATIONSHIP (ID, SYNCID, ACTIONCODE)
                select INSERTED.ID, newid(), 1
                from INSERTED
                left outer join dbo.TA_CONSTITUENT c on c.ID = INSERTED.RELATIONSHIPCONSTITUENTID
                left outer join dbo.TA_CONSTITUENT rc on rc.ID = INSERTED.RECIPROCALCONSTITUENTID
                -- don't sync records for groups

                where not exists(select 'x'
                                                 from dbo.GROUPDATA d
                                                 where (d.ID = INSERTED.RELATIONSHIPCONSTITUENTID or d.ID = RECIPROCALCONSTITUENTID)
                                                 and d.GROUPTYPECODE = 1)
                    and ((c.account_id < rc.account_id OR
                            (c.account_id = rc.account_id AND c.name_id < rc.name_id)) or c.ID is null or rc.id is null);
            end
        end