Back to OIM Explorer

dbo.QER_TUPersonWantsOrg

Database TriggerSQL_TRIGGERSandbox DB

Database Trigger on PersonWantsOrg. HOCallMethod -> PersonWantsOrg.MakeDecisionOnInsertAsync at line 75; HOCallMethod -> personwantsorg.Abort at line 75; HOCallMethod -> PersonWantsOrg.MakeDecisionOnInsertAsync at line 76; HOCallMethod -> personwantsorg.Abort at line 76

Source: sandbox-db sys.sql_modules

Source size: 16.836 characters

Interpretation

  • Database trigger. Treat parent table and enqueue/object-layer calls as the main relation points.
  • Object-layer bridge detected through QBM_PJobCreate helper usage.
  • DBQueue relation detected. Follow the task procedure and referenced-by list for async processing.

Relations

  • HOCallMethod -> PersonWantsOrg.MakeDecisionOnInsertAsync at line 75
  • HOCallMethod -> personwantsorg.Abort at line 75
  • HOCallMethod -> PersonWantsOrg.MakeDecisionOnInsertAsync at line 76
  • HOCallMethod -> personwantsorg.Abort at line 76
  • HOCallMethod -> PersonWantsOrg.MakeDecisionOnInsertAsync at line 88
  • HOCallMethod -> personwantsorg.Abort at line 88
  • HOCallMethod -> personwantsorg.Abort at line 102
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 32
  • Bulk DBQueue insert -> Assigned at line 32
  • Bulk DBQueue insert -> QER-K-ShoppingRackCheckWaiting / QER_ZITShopCheckWaiting at line 32
  • Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 32
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 32
  • Bulk DBQueue insert -> Assigned at line 36
  • Bulk DBQueue insert -> QER-K-ShoppingRackCheckWaiting / QER_ZITShopCheckWaiting at line 36
  • Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 36
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 36
  • Bulk DBQueue insert -> QER-K-ShoppingRackCheckWaiting / QER_ZITShopCheckWaiting at line 40
  • Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 40
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 40
  • Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 43
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 43
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 49
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 49
  • Bulk DBQueue insert -> QER-K-ShoppingRackCheckDecision / QER_ZITShopCheckDecision at line 49
  • Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 75
  • Bulk DBQueue insert -> QER-K-ShoppingRackCheckDecision / QER_ZITShopCheckDecision at line 75
  • Bulk DBQueue insert -> QER-K-ShoppingRackCheckDecision / QER_ZITShopCheckDecision at line 76
  • References QBM_PJobCreate*
  • References QBM_PJobCreate_HOCallMethod*
  • References QBM_PDBQueueInsert_Bulk
  • Trigger parent table: PersonWantsOrg

Typed Edges

  • calls object method PersonWantsOrg.MakeDecisionOnInsertAsync HOCallMethod -> PersonWantsOrg.MakeDecisionOnInsertAsync at line 75
  • calls object method personwantsorg.Abort HOCallMethod -> personwantsorg.Abort at line 75
  • queues DBQueue task QER_ZITShopHelperFill at line 32 Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 32
  • queues DBQueue task Assigned at line 32 Bulk DBQueue insert -> Assigned at line 32
  • queues DBQueue task QER_ZITShopCheckWaiting at line 32 Bulk DBQueue insert -> QER-K-ShoppingRackCheckWaiting / QER_ZITShopCheckWaiting at line 32
  • queues DBQueue task QER_ZITShopRepairClosed at line 32 Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 32
  • queues DBQueue task Assigned at line 36 Bulk DBQueue insert -> Assigned at line 36
  • queues DBQueue task QER_ZITShopCheckWaiting at line 36 Bulk DBQueue insert -> QER-K-ShoppingRackCheckWaiting / QER_ZITShopCheckWaiting at line 36
  • queues DBQueue task QER_ZITShopRepairClosed at line 36 Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 36
  • queues DBQueue task QER_ZITShopHelperFill at line 36 Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 36
  • queues DBQueue task QER_ZITShopCheckWaiting at line 40 Bulk DBQueue insert -> QER-K-ShoppingRackCheckWaiting / QER_ZITShopCheckWaiting at line 40
  • queues DBQueue task QER_ZITShopRepairClosed at line 40 Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 40
  • queues DBQueue task QER_ZITShopHelperFill at line 40 Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 40
  • queues DBQueue task QER_ZITShopRepairClosed at line 43 Bulk DBQueue insert -> QER-K-ITShopRepairClosed / QER_ZITShopRepairClosed at line 43
  • queues DBQueue task QER_ZITShopHelperFill at line 43 Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 43
  • queues DBQueue task QER_ZITShopHelperFill at line 49 Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 49
  • queues DBQueue task QER_ZITShopCheckDecision at line 49 Bulk DBQueue insert -> QER-K-ShoppingRackCheckDecision / QER_ZITShopCheckDecision at line 49
  • queues DBQueue task QER_ZITShopHelperFill at line 75 Bulk DBQueue insert -> QER-K-ShoppingRackPWOHelperPWO / QER_ZITShopHelperFill at line 75
  • queues DBQueue task QER_ZITShopCheckDecision at line 75 Bulk DBQueue insert -> QER-K-ShoppingRackCheckDecision / QER_ZITShopCheckDecision at line 75
  • queues DBQueue task QER_ZITShopCheckDecision at line 76 Bulk DBQueue insert -> QER-K-ShoppingRackCheckDecision / QER_ZITShopCheckDecision at line 76
  • trigger on table PersonWantsOrg Trigger parent table: PersonWantsOrg
  • references source dbo.QBM_FCVParameter1AsOneInClause source text reference
  • references source dbo.QBM_FCVStringToBit source text reference
  • references source dbo.QBM_FGIColumnUpdatedOthers source text reference
  • references source dbo.QBM_FGIConfigparmValue source text reference
  • references source dbo.QBM_FGISessionContext source text reference
  • references source dbo.QER_FGIGenProcIDForPWO source text reference
  • references source dbo.QER_FGIPWOStateFinalError source text reference
  • references source dbo.QER_FGIPWOTaskToUse source text reference
  • references source dbo.QBM_PDBQueueInsert_Bulk source text reference
  • references source dbo.QBM_PJobCreate source text reference
  • references source dbo.QBM_PJobCreate_HOCallMethod source text reference
  • references source dbo.QBM_PJobCreate_HOCallMethod_L source text reference
  • references source dbo.QBM_PJobCreate_SQLDel source text reference
  • references source dbo.QBM_PJobCreate_SQLDel_B source text reference
  • references source dbo.QBM_PJobCreate_SQLDel_L source text reference
  • references source dbo.QBM_PSessionErrorAdd source text reference
  • references source dbo.QER_PITShopHelperFill source text reference
  • references source dbo.QER_PITShopHelperFill_bulk source text reference
  • references source dbo.QER_PITShopOrderResetOneLevel source text reference

Complete Source

SQL649 lines
1CREATE trigger QER_TUPersonWantsOrg2  ON PersonWantsOrg FOR3UPDATE NOT FOR Replication4AS5BEGIN6  DECLARE @uid_Personwantsorg varchar(38)7  DECLARE @isNewDecisionLevel BIT8  DECLARE @DecisionOnInsert int = 09  DECLARE @IsOrderStarted BIT10  DECLARE @PWOBuffer QBM_YCursorBuffer11  DECLARE @ElementCount int12  DECLARE @ElementIndex int13  DECLARE @ElementLast int14  DECLARE @SQLCmd nvarchar(max)15  DECLARE @CursorBuffer QBM_YCursorBuffer16  DECLARE @BasisObjectKey varchar(138)17  DECLARE @PWOsAreFinished QBM_YParameterList18  DECLARE @CountPWOsAreFinished int19  DECLARE @PWOsToResetGenProcID QBM_YParameterList20  DECLARE @CountPWOsToResetGenProcID int21  DECLARE @GenProcIDToUse varchar(38)22  DECLARE @UID_PWOStateFinalError varchar(64)23  DECLARE @CfgUseGenProcID BIT = dbo.QBM_FCVStringToBit(dbo.QBM_FGIConfigparmValue('Common\ProcessState\UseGenProcIDFromPWO'))24  DECLARE @PWOsToFillHelper QBM_YParameterlist25  DECLARE @PWOsToFillHasObject QBM_YParameterlist26  DECLARE @PWOHelperPWOToDeleteImmediate QBM_YParameterList27  DECLARE @PWOHelperPWOToDeleteLater QBM_YParameterList28  DECLARE @DeleteWhereClause nvarchar(max)29  DECLARE @newDecisionLevel int30  DECLARE @GenProcID varchar(38) = dbo.QBM_FGISessionContext('')31  DECLARE @PWOTaskToUse varchar(38) = dbo.QER_FGIPWOTaskToUse()32  DECLARE @XUser nvarchar(64) = object_name(@@procid)33  DECLARE @Xdate datetime = getutcdate()34  BEGIN TRY35    IF EXISTS(36      SELECT TOP 1 137      FROM inserted)38    GOTO start39    IF EXISTS(40      SELECT TOP 1 141      FROM deleted)42    GOTO start43    RETURN start:44    IF45    UPDATE(UID_ITShopOrgFinal) AND dbo.QBM_FGIColumnUpdatedOthers('PersonWantsOrg',46    'UID_ITShopOrgFinal',47    columns_updated()) = 0 AND NOT EXISTS(48    SELECT TOP 1 149    FROM inserted i50    WHERE51      i.DecisionLevel > 0)52    BEGIN53      GOTO ende54    END55    IF dbo.QBM_FGIConfigparmValue('QER\ITShop\DecisionOnInsert') > ' '56    BEGIN57      SELECT @DecisionOnInsert = 158    END59    IF60    UPDATE(Orderstate) OR61    UPDATE(UID_QERWorkingMethod)62    BEGIN63      IF EXISTS(64        SELECT TOP 1 165        FROM inserted i66        JOIN PersonWantsOrg pwo67          ON i.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg68        JOIN QER_VPWOOrderState s69          ON pwo.OrderState = s.OrderState70        WHERE71          sign(len(isnull(pwo.UID_QERWorkingMethod, ''))) ^ s.HasWorkingMethod = 1)72      BEGIN73        RAISERROR('#LDS#Invalid combination of Orderstate and QERWorkingMethod.|',74        18,75        1)76          WITH nowait77      END78    END79    IF80    UPDATE(uid_Org) OR81    UPDATE(UID_ITShopOrgFinal) OR82    UPDATE(OrderState)83    BEGIN84      INSERT INTO @PWOsToFillHasObject(Parameter1,85      Parameter2)86      SELECT87        pwo.UID_PersonWantsOrg,88        @GenProcID89      FROM personwantsorg pwo90      JOIN deleted d91        ON pwo.uid_personwantsorg = d.uid_personwantsorg AND pwo.OrderState IN('OrderProduct',92      'OrderProlongate',93      'OrderUnsubscribe')94      WHERE95        (isnull(pwo.uid_Org, '') <> isnull(d.UID_Org, '') OR isnull(pwo.UID_ITShopOrgFinal, '') <> isnull(d.UID_ITShopOrgFinal,96      '') OR(isnull(pwo.OrderState, '') = 'OrderProlongate' AND isnull(d.OrderState, '') <> 'OrderProlongate'))97    END98    IF NOT99    UPDATE(UID_PersonWantsOrgParent)100    BEGIN101      IF dbo.QBM_FGIColumnUpdatedOthers('PersonWantsOrg',102      'OrderState',103      columns_updated()) = 1 AND dbo.QBM_FGIColumnUpdatedOthers('PersonWantsOrg',104      'DecisionLevel',105      columns_updated()) = 1106      BEGIN107        INSERT INTO @PWOsToFillHelper(Parameter1,108        Parameter2,109        Parameter3,110        HasContentFull)111        SELECT112          pwo.uid_personwantsorg,113          @GenProcID,114          '1' AS CurrentLevelOnly,115        CASE116          WHEN isnull(d.DecisionLevel,117        0) <> isnull(pwo.DecisionLevel,118        0) THEN119        1120          WHEN d.OrderState NOT IN('OrderProlongate',121        'OrderUnsubscribe') AND pwo.OrderState IN('OrderProlongate',122        'OrderUnsubscribe') THEN123        1124        ELSE 0125        END AS isNewDecisionLevel126        FROM deleted d127        JOIN personwantsorg pwo128          ON d.uid_personwantsorg = pwo.uid_personwantsorg129        WHERE130          datediff(ss,131        isnull(d.Xdateinserted, '1997-01-01'),132        getUTCDate()) < 10133      END134    END135    IF dbo.QBM_FGIColumnUpdatedOthers('PersonWantsOrg',136    'OrderState',137    columns_updated()) = 1 AND dbo.QBM_FGIColumnUpdatedOthers('PersonWantsOrg',138    'DecisionLevel',139    columns_updated()) = 1 AND(140    UPDATE(UID_PersonHead) OR141    UPDATE(ReasonHead) OR142    UPDATE(DateHead))143    BEGIN144      DECLARE @DBQueueElements_01 QBM_YDBQueueRaw145      INSERT INTO @DBQueueElements_01(object,146      subobject,147      genprocid)148      SELECT149        x.uid,150        NULL,151        @GenProcID152      FROM(153      SELECT pwo.uid_personwantsorg AS uid154      FROM deleted d155      JOIN personwantsorg pwo156        ON d.uid_personwantsorg = pwo.uid_personwantsorg157      WHERE158        (isnull(d.DateHead, '1899-12-30') <> isnull(pwo.DateHead, '1899-12-30') OR isnull(d.ReasonHead, N '') <> isnull(pwo.ReasonHead,159      N '')) AND(isnull(d.UID_PersonHead, '') <> isnull(pwo.UID_PersonHead, '') OR EXISTS(160      SELECT TOP 1 1161      FROM pwohelperpwo h162      WHERE163        h.uid_personwantsorg = pwo.uid_personwantsorg AND h.LevelNumber = pwo.decisionlevel AND(h.UID_PersonAdditional > ' ' OR h.UID_PersonInsteadOf164      > ' ' OR h.Decision = '-')))165      UNION166      SELECT h.UID_PersonWantsOrg167      FROM deleted d168      JOIN PersonWantsOrg pwo169        ON d.uid_personwantsorg = pwo.uid_personwantsorg170      JOIN PWOHelperPWO h171        ON h.UID_PWORulerOrigin = pwo.UID_PersonWantsOrg172      WHERE173        d.OrderState IN('Assigned', 'Granted', 'New', 'OrderProduct', 'OrderProlongate', 'OrderUnsubscribe',174      'Waiting') AND pwo.OrderState IN('Aborted', 'Dismissed', 'Unsubscribed')) AS x175      EXEC QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackPWOHelperPWO',176        @DBQueueElements_01177    END178    IF179    UPDATE(UID_Department) OR180    UPDATE(UID_ProfitCenter)181    BEGIN182      IF @PWOTaskToUse > ' '183      BEGIN184        DECLARE @DBQueueElements_02 QBM_YDBQueueRaw185        INSERT INTO @DBQueueElements_02(object,186        subobject,187        genprocid)188        SELECT189          x.uid,190          NULL,191          @GenProcID192        FROM(193        SELECT d.UID_PersonWantsOrg AS uid194        FROM deleted d195        JOIN PersonWantsOrg pwo196          ON d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg197        WHERE198          isnull(d.UID_Department, '') <> isnull(pwo.UID_Department, '') OR isnull(d.UID_ProfitCenter, '') <> isnull(pwo.UID_ProfitCenter,199        '')) AS x200        EXEC QBM_PDBQueueInsert_Bulk @PWOTaskToUse,201          @DBQueueElements_02202      END203    END204    IF205    UPDATE(OrderState)206    BEGIN207      DECLARE @DBQueueElements_03 QBM_YDBQueueRaw208      INSERT INTO @DBQueueElements_03(object,209      subobject,210      genprocid)211      SELECT212        x.uid,213        NULL,214        @GenProcID215      FROM(216      SELECT pwo.UID_PersonWantsOrg AS uid217      FROM deleted d218      JOIN personwantsorg pwo219        ON d.uid_personwantsorg = pwo.uid_Personwantsorg220      WHERE221        d.OrderState IN('Assigned', 'OrderProlongate', 'OrderUnsubscribe') AND pwo.OrderState IN('Aborted',222      'Dismissed', 'Unsubscribed')) AS x223      EXEC QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackCheckWaiting',224        @DBQueueElements_03225      DECLARE @DBQueueElements_04 QBM_YDBQueueRaw226      INSERT INTO @DBQueueElements_04(object,227      subobject,228      genprocid)229      SELECT230        x.uid,231        NULL,232        @GenProcID233      FROM(234      SELECT pwo.UID_PersonWantsOrg AS uid235      FROM deleted d236      JOIN personwantsorg pwo237        ON d.uid_PersonWantsOrg = pwo.uid_PersonWantsOrg238      JOIN QER_VPWOPersonPropertyReset r239        ON pwo.UID_PersonWantsOrg = r.UID_PersonWantsOrg240      WHERE241        d.OrderState IN('Assigned', 'Granted', 'New', 'OrderProduct', 'OrderProlongate', 'OrderUnsubscribe',242      'Waiting')) AS x243      EXEC QBM_PDBQueueInsert_Bulk 'QER-K-ITShopRepairClosed',244        @DBQueueElements_04245      INSERT INTO @PWOsAreFinished(Parameter1)246      SELECT pwo.uid_personwantsorg247      FROM personwantsorg pwo248      JOIN deleted d249        ON pwo.uid_Personwantsorg = d.uid_personwantsorg250      WHERE251        pwo.OrderState IN('Aborted',252      'Assigned',253      'Dismissed',254      'Granted',255      'New',256      'Unsubscribed',257      'Waiting') AND d.OrderState IN('OrderProduct',258      'OrderProlongate',259      'OrderUnsubscribe')260      SELECT @CountPWOsAreFinished = @@ROWCOUNT261      DECLARE @DBQueueElements_05 QBM_YDBQueueRaw262      INSERT INTO @DBQueueElements_05(object,263      subobject,264      genprocid)265      SELECT266        x.uid,267        NULL,268        @GenProcID269      FROM(270      SELECT d.UID_PersonWantsOrg AS uid271      FROM deleted d272      JOIN PersonWantsOrg pwo273        ON d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg274      LEFT275      OUTER276      JOIN @PWOsAreFinished fi277        ON fi.Parameter1 = d.UID_PersonWantsOrg278      WHERE279        isnull(d.OrderState, '') <> isnull(pwo.OrderState, '') AND fi.Parameter1 IS NULL) AS x280      EXEC QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackPWOHelperPWO',281        @DBQueueElements_05282      INSERT INTO @PWOsToResetGenProcID(Parameter1)283      SELECT pwo.uid_personwantsorg284      FROM personwantsorg pwo285      JOIN deleted d286        ON pwo.uid_Personwantsorg = d.uid_personwantsorg287      WHERE288        pwo.OrderState IN('Aborted',289      'Assigned',290      'Dismissed',291      'Unsubscribed') AND d.OrderState IN('OrderProduct',292      'OrderProlongate',293      'OrderUnsubscribe',294      'Granted',295      'New',296      'Waiting')297      SELECT @CountPWOsToResetGenProcID = @@ROWCOUNT298      IF @CountPWOsAreFinished > 0299      BEGIN300        INSERT INTO @PWOHelperPWOToDeleteLater(Parameter1)301        SELECT h.XObjectKey302        FROM PWOHelperPWO h303          WITH(readpast)304        WHERE305          uid_Personwantsorg IN(306        SELECT Parameter1307        FROM @PWOsAreFinished)308        IF @@ROWCOUNT > 0309        BEGIN310          EXEC QBM_PJobCreate_SQLDel_L 'PWOHelperPWO',311            @PWOHelperPWOToDeleteLater,312            @GenProcID = @GenProcID,313            @AdditionalObjectKeysAffected = DEFAULT,314            @Retries = 5,315            @isToFreezeOnError = 1316        END317        IF EXISTS(318          SELECT TOP 1 1319          FROM HelperPWOPersonHasObject h320          WITH(readpast)321        JOIN @PWOsAreFinished f322          ON h.UID_PersonWantsOrg = f.Parameter1)323        BEGIN324          SELECT325            @DeleteWhereClause = 'UID_PersonWantsOrg in ' + dbo.QBM_FCVParameter1AsOneInClause(@PWOsAreFinished)326          EXEC QBM_PJobCreate_SQLDel_B 'HelperPWOPersonHasObject',327            @whereclause = @DeleteWhereClause,328            @GenProcID = @GenProcID,329            @AdditionalObjectKeysAffected = DEFAULT,330            @isToFreezeOnError = 1,331            @Retries = 5332        END333        IF EXISTS(334          SELECT TOP 1 1335          FROM HelperPWOCompliance h336          WITH(readpast)337        JOIN @PWOsAreFinished f338          ON h.UID_PersonWantsOrg = f.Parameter1)339        BEGIN340          SELECT341            @DeleteWhereClause = 'UID_PersonWantsOrg in ' + dbo.QBM_FCVParameter1AsOneInClause(@PWOsAreFinished)342          EXEC QBM_PJobCreate_SQLDel_B 'HelperPWOCompliance',343            @whereclause = @DeleteWhereClause,344            @GenProcID = @GenProcID,345            @AdditionalObjectKeysAffected = DEFAULT,346            @isToFreezeOnError = 1,347            @Retries = 5348        END349      END350      IF @CountPWOsToResetGenProcID > 0351      BEGIN352        UPDATE PersonWantsOrg353        SET GenProcID = NULL,354        XDateUpdated = @Xdate,355        XUserUpdated = @XUser356        WHERE357          uid_Personwantsorg IN(358        SELECT Parameter1359        FROM @PWOsToResetGenProcID)360      END361    END362    IF363    UPDATE(DecisionLevel) OR364    UPDATE(OrderState) OR365    UPDATE(UID_PersonInserted) OR366    UPDATE(UID_PersonOrdered)367    BEGIN368      DELETE @PWOBuffer369      INSERT INTO @PWOBuffer(UID1,370      Bit1,371      int1,372      Int2)373      SELECT374        pwo.uid_personwantsorg,375      CASE376        WHEN isnull(d.DecisionLevel,377      0) <> isnull(pwo.DecisionLevel,378      0) THEN379      1380        WHEN d.OrderState NOT IN('OrderProlongate',381      'OrderUnsubscribe') AND pwo.OrderState IN('OrderProlongate',382      'OrderUnsubscribe') THEN383      1384      ELSE 0385      END AS isNewDecisionLevel,386      pwo.DecisionLevel,387      CASE388        WHEN d.OrderState NOT IN('OrderProlongate',389      'OrderUnsubscribe') AND pwo.OrderState IN('OrderProlongate',390      'OrderUnsubscribe') THEN391      1392      ELSE 0393      END AS IsOrderStarted394      FROM deleted d395      JOIN Personwantsorg pwo396        ON d.uid_personwantsorg = pwo.uid_personwantsorg397      LEFT398      OUTER399      JOIN @PWOsAreFinished fi400        ON fi.Parameter1 = d.UID_PersonWantsOrg401      WHERE402        d.DecisionLevel <> pwo.DecisionLevel AND fi.Parameter1 IS NULL OR pwo.OrderState IN('OrderProduct',403      'OrderProlongate',404      'OrderUnsubscribe')405      SELECT @ElementCount = @@ROWCOUNT406      SELECT @ElementIndex = @@IDENTITY - @ElementCount +1407      SELECT @ElementLast = @@IDENTITY408      WHILE @ElementIndex <= @ElementLast409      BEGIN410        SELECT411          TOP 1 @uid_Personwantsorg = bu.UID1,412          @isNewDecisionLevel = bu.bit1,413          @newDecisionLevel = bu.int1,414          @IsOrderStarted = sign(bu.Int2)415        FROM @PWOBuffer bu416        WHERE417          bu.ElementIndex = @ElementIndex418        IF @isNewDecisionLevel = 1419        BEGIN420          EXEC QER_PITShopOrderResetOneLevel @uid_personwantsorg,421            @newDecisionLevel,422            @GenProcID423        END424        SELECT @ElementIndex += 1425      END426      INSERT INTO @PWOsToFillHelper(Parameter1,427      Parameter2,428      Parameter3,429      HasContentFull)430      SELECT431        bu.UID1 AS UID_PersonwantsOrg,432        @GenProcID,433        '1' AS CurrentLevelOnly,434        bu.bit1 AS IsNewDecisionLevel435      FROM @PWOBuffer bu436      WHERE437        (sign(bu.Int2) = 1 AND @DecisionOnInsert = 1 OR sign(bu.Int2) = 0) AND NOT EXISTS(438      SELECT TOP 1 1439      FROM @PWOsToFillHelper e440      WHERE441        e.Parameter1 = bu.UID1)442      DECLARE @DBQueueElements_06 QBM_YDBQueueRaw443      INSERT INTO @DBQueueElements_06(object,444      subobject,445      genprocid)446      SELECT447        x.uid,448        NULL,449        @GenProcID450      FROM(451      SELECT i.UID_PersonWantsOrg AS uid452      FROM inserted i453      LEFT454      OUTER455      JOIN @PWOsAreFinished fi456        ON fi.Parameter1 = i.UID_PersonWantsOrg457      WHERE458        fi.Parameter1 IS NULL) AS x459      EXEC QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackPWOHelperPWO',460        @DBQueueElements_06461      EXEC QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackCheckDecision',462        @DBQueueElements_06463    END464    IF465    UPDATE(OrderState) OR466    UPDATE(DecisionLevel)467    BEGIN468      INSERT INTO @PWOHelperPWOToDeleteImmediate(Parameter1)469      SELECT h.UID_PWOHelperPWO470      FROM PWOHelperPWO h471        WITH(readpast)472      JOIN inserted i473        ON i.uid_PersonWantsOrg = h.uid_PersonWantsOrg474      LEFT475      OUTER476      JOIN @PWOsAreFinished fi477        ON fi.Parameter1 = i.UID_PersonWantsOrg478      WHERE479        UID_PWODecisionRule = 'QER-PWODecisionRule-QP' AND fi.Parameter1 IS NULL480    END481    IF482    UPDATE(isReserved)483    BEGIN484      INSERT INTO @PWOHelperPWOToDeleteImmediate(Parameter1)485      SELECT h.UID_PWOHelperPWO486      FROM PWOHelperPWO h487        WITH(readpast)488      LEFT489      OUTER490      JOIN @PWOsAreFinished fi491        ON fi.Parameter1 = h.UID_PersonWantsOrg492      WHERE493        h.UID_PWODecisionRule = 'QER-PWODecisionRule-QP' AND fi.Parameter1 IS NULL AND EXISTS(494      SELECT TOP 1 1495      FROM deleted d496      JOIN personwantsorg pwo497        ON d.uid_PersonWantsOrg = pwo.uid_PersonWantsOrg AND d.isreserved = 1 AND pwo.isReserved = 0498      WHERE499        pwo.UID_PersonWantsOrg = h.UID_PersonWantsOrg)500    END501    IF EXISTS(502      SELECT TOP 1 1503      FROM @PWOHelperPWOToDeleteImmediate)504    BEGIN505      DELETE PWOHelperPWO506      FROM PWOHelperPWO h507      WHERE508        h.UID_PWOHelperPWO IN(509      SELECT d.Parameter1510      FROM @PWOHelperPWOToDeleteImmediate d)511    END512    IF EXISTS(513      SELECT TOP 1 1514      FROM @PWOsToFillHelper h515      JOIN @PWOsAreFinished fi516        ON h.Parameter1 = fi.Parameter1)517    BEGIN518      DELETE @PWOsToFillHelper519      WHERE520        Parameter1 IN(521      SELECT Parameter1522      FROM @PWOsAreFinished)523    END524    IF EXISTS(525      SELECT TOP 1 1526      FROM @PWOsToFillHelper)527    BEGIN528      IF @DecisionOnInsert = 1529      BEGIN530        DECLARE @PWOsToFire QBM_YParameterList531        INSERT INTO @PWOsToFire(Parameter1)532        SELECT pwo.XObjectKey533        FROM @PWOsToFillHelper i534        JOIN PersonWantsOrg pwo535          ON i.Parameter1 = pwo.UID_PersonWantsOrg536        JOIN deleted d537          ON d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg538        WHERE539          pwo.OrderState IN('OrderProlongate',540        'OrderUnsubscribe') AND d.OrderState NOT IN('OrderProlongate',541        'OrderUnsubscribe')542        EXEC QBM_PJobCreate_HOCallMethod_L @objecttype = 'PersonWantsOrg',543          @XObjectKeys = @PWOsToFire,544          @save = 1,545          @MethodName = 'MakeDecisionOnInsertAsync',546          @GenProcID = @GenProcID,547          @AdditionalObjectKeysAffected = DEFAULT,548          @Retries = 3,549          @isToFreezeOnError = 1,550          @WhereClauseAdditional = 'DecisionLevel = 0 and OrderState in (''OrderProlongate'', ''OrderUnsubscribe'')',551          @checkForExisting = 1552        DELETE @PWOsToFillHelper553        FROM @PWOsToFillHelper i554        JOIN PersonWantsOrg pwo555          ON i.Parameter1 = pwo.UID_PersonWantsOrg556        JOIN deleted d557          ON d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg558        WHERE559          pwo.OrderState IN('OrderProlongate',560        'OrderUnsubscribe') AND d.OrderState NOT IN('OrderProlongate',561        'OrderUnsubscribe')562      END563      EXEC QER_PITShopHelperFill_bulk @PWOsToFillHelper564    END565    IF EXISTS(566      SELECT TOP 1 1567      FROM @PWOsToFillHasObject)568    BEGIN569      EXEC QER_PITShopPersonHasObjFill_b @PWOsToFillHasObject,570        @IsCalledFromTrigger = 0571    END572    IF573    UPDATE(OrderState) OR574    UPDATE(UID_PersonHead) OR575    UPDATE(UID_PersonOrdered) OR576    UPDATE(UID_PersonInserted)577    BEGIN578      DELETE @CursorBuffer579      INSERT INTO @CursorBuffer(UID1,580      ObjectKey1,581      UID2)582      SELECT583        pwo.uid_personwantsorg,584        pwo.XObjectKey,585        dbo.QER_FGIGenProcIDForPWO(pwo.GenProcID,586        @GenProcID,587        @CfgUseGenProcID) AS GenProcID588      FROM deleted d589      JOIN PersonWantsOrg pwo590        ON pwo.UID_PersonWantsOrg = d.UID_PersonWantsOrg AND pwo.OrderState IN('Assigned',591      'Granted',592      'New',593      'OrderProduct',594      'OrderProlongate',595      'OrderUnsubscribe',596      'Waiting')597      JOIN Delegation de598        ON pwo.UID_PersonWantsOrg = de.UID_PersonWantsOrg599      LEFT600      OUTER601      JOIN Person p1602        ON de.UID_PersonSender = p1.UID_Person603      LEFT604      OUTER605      JOIN Person p2606        ON de.UID_PersonReceiver = p2.UID_Person607      WHERE608        p1.UID_Person IS NULL OR p2.UID_Person IS NULL609      SELECT @ElementCount = @@ROWCOUNT610      SELECT @ElementIndex = @@IDENTITY - @ElementCount +1611      SELECT @ElementLast = @@IDENTITY612      WHILE @ElementIndex <= @ElementLast613      BEGIN614        SELECT615          TOP 1 @uid_personwantsorg = bu.UID1,616          @BasisObjectKey = bu.ObjectKey1,617          @GenProcIDToUse = bu.UID2618        FROM @CursorBuffer bu619        WHERE620          bu.ElementIndex = @ElementIndex621        SELECT @SQLcmd = N 'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N ''''622        SELECT @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg)623        EXEC QBM_PJobCreate_HOCallMethod @objecttype = 'personwantsorg',624          @whereclause = @SQLcmd,625          @save = 1,626          @MethodName = 'Abort',627          @GenProcID = @GenProcIDToUse,628          @ObjectKeysAffected = DEFAULT,629          @param1 = '#LDS#Closing delegation because its source was deleted.|',630          @param2 = @UID_PWOStateFinalError,631          @Retries = 3,632          @isToFreezeOnError = 1,633          @BasisObjectKey = @BasisObjectKey,634          @checkForExisting = 1,635          @WhereClauseAdditional = ' OrderState in (''Assigned'', ''Granted'', ''New'', ''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'', ''Waiting'')'636        SELECT @ElementIndex += 1637      END638    END639  END TRY640  BEGIN CATCH641    EXEC QBM_PSessionErrorAdd DEFAULT642    RAISERROR('',643    18,644    1)645      WITH NOWAIT646  END CATCH647  ende:648  RETURN649END
Open raw exported source
SQL ยท Raw107 lines
1create   trigger QER_TUPersonWantsOrg on PersonWantsOrg  for UPDATE not for Replication as begin  declare @uid_Personwantsorg varchar(38) declare2 @isNewDecisionLevel bit declare @DecisionOnInsert int = 0 declare @IsOrderStarted bit declare @PWOBuffer QBM_YCursorBuffer declare @ElementCount int declare3 @ElementIndex int declare @ElementLast int declare @SQLCmd nvarchar(max) declare @CursorBuffer QBM_YCursorBuffer declare @BasisObjectKey varchar(138) 4declare @PWOsAreFinished QBM_YParameterList declare @CountPWOsAreFinished int declare @PWOsToResetGenProcID QBM_YParameterList declare @CountPWOsToResetGenProcID5 int declare @GenProcIDToUse varchar(38) declare @UID_PWOStateFinalError varchar(64) declare @CfgUseGenProcID bit = dbo.QBM_FCVStringToBit(dbo.QBM_FGIConfigparmValue6('Common\ProcessState\UseGenProcIDFromPWO')) declare @PWOsToFillHelper QBM_YParameterlist      declare @PWOsToFillHasObject QBM_YParameterlist declare 7@PWOHelperPWOToDeleteImmediate QBM_YParameterList declare @PWOHelperPWOToDeleteLater QBM_YParameterList declare @DeleteWhereClause nvarchar(max) declare8 @newDecisionLevel int declare @GenProcID varchar(38) = dbo.QBM_FGISessionContext('') declare @PWOTaskToUse varchar(38) = dbo.QER_FGIPWOTaskToUse() declare9 @XUser nvarchar(64) = object_name(@@procid) declare @Xdate datetime = getutcdate() BEGIN TRY if exists (select top 1 1 from inserted) goto start if exists10 (select top 1 1 from deleted) goto start return start:  if update(UID_ITShopOrgFinal) and dbo.QBM_FGIColumnUpdatedOthers ('PersonWantsOrg', 'UID_ITShopOrgFinal'11, columns_updated()) = 0 and not exists (select top 1 1 from inserted i where i.DecisionLevel > 0 ) begin  goto ende end if dbo.QBM_FGIConfigparmValue(12'QER\ITShop\DecisionOnInsert') > ' ' begin select @DecisionOnInsert = 1 end if update(Orderstate) or update(UID_QERWorkingMethod) begin if exists (select13 top 1 1  from inserted i join PersonWantsOrg pwo on i.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg join QER_VPWOOrderState s on pwo.OrderState = s.OrderState14 where  sign(len(isnull(pwo.UID_QERWorkingMethod, ''))) ^ s.HasWorkingMethod = 1 ) begin raiserror('#LDS#Invalid combination of Orderstate and QERWorkingMethod.|'15, 18, 1) with nowait end end if update(uid_Org) or update(UID_ITShopOrgFinal)  or update(OrderState) begin insert into @PWOsToFillHasObject(Parameter1,16 Parameter2) select pwo.UID_PersonWantsOrg , @GenProcID from personwantsorg pwo join deleted d on pwo.uid_personwantsorg = d.uid_personwantsorg   and pwo.OrderState17 in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe') where (isnull(pwo.uid_Org, '') <> isnull(d.UID_Org, '') or isnull(pwo.UID_ITShopOrgFinal, ''18) <> isnull(d.UID_ITShopOrgFinal, '')  or ( isnull(pwo.OrderState, '') = 'OrderProlongate' and isnull(d.OrderState, '') <> 'OrderProlongate' )  ) end  19if not update(UID_PersonWantsOrgParent) begin      if dbo.QBM_FGIColumnUpdatedOthers ('PersonWantsOrg', 'OrderState', columns_updated()) = 1 and dbo.QBM_FGIColumnUpdatedOthers20 ('PersonWantsOrg', 'DecisionLevel', columns_updated()) = 1 begin insert into @PWOsToFillHelper(Parameter1, Parameter2, Parameter3, HasContentFull) select21 pwo.uid_personwantsorg , @GenProcID  , '1' as CurrentLevelOnly  , case when isnull(d.DecisionLevel,0) <> isnull(pwo.DecisionLevel, 0) then 1 when d.OrderState22 not in ( 'OrderProlongate' , 'OrderUnsubscribe') and pwo.OrderState in ( 'OrderProlongate' , 'OrderUnsubscribe') then 1 else 0 end as isNewDecisionLevel23 from deleted d join personwantsorg pwo on d.uid_personwantsorg = pwo.uid_personwantsorg where datediff(ss, isnull(d.Xdateinserted, '1997-01-01') , getUTCDate24()) < 10 end  end    if dbo.QBM_FGIColumnUpdatedOthers ('PersonWantsOrg', 'OrderState', columns_updated()) = 1 and dbo.QBM_FGIColumnUpdatedOthers ('PersonWantsOrg'25, 'DecisionLevel', columns_updated()) = 1  and (update(UID_PersonHead) or update(ReasonHead) or update(DateHead) ) begin declare @DBQueueElements_01 QBM_YDBQueueRaw26 insert into @DBQueueElements_01 (object, subobject, genprocid) select x.uid, null, @GenProcID from (select pwo.uid_personwantsorg as uid from deleted 27d join personwantsorg pwo on d.uid_personwantsorg = pwo.uid_personwantsorg where (isnull(d.DateHead, '1899-12-30') <> isnull(pwo.DateHead, '1899-12-30'28) or isnull(d.ReasonHead, N'') <> isnull(pwo.ReasonHead, N'') ) and ( isnull(d.UID_PersonHead, '') <> isnull(pwo.UID_PersonHead, '')   or exists (select29 top 1 1 from pwohelperpwo h where h.uid_personwantsorg = pwo.uid_personwantsorg and h.LevelNumber = pwo.decisionlevel  and (h.UID_PersonAdditional > ' '30 or h.UID_PersonInsteadOf > ' '  or h.Decision = '-' ) ) ) union select h.UID_PersonWantsOrg from deleted d join PersonWantsOrg pwo on d.uid_personwantsorg31 = pwo.uid_personwantsorg join PWOHelperPWO h on h.UID_PWORulerOrigin = pwo.UID_PersonWantsOrg    where d.OrderState in ('Assigned', 'Granted', 'New', 32'OrderProduct', 'OrderProlongate', 'OrderUnsubscribe', 'Waiting') and pwo.OrderState in ('Aborted', 'Dismissed', 'Unsubscribed' ) ) as x  exec QBM_PDBQueueInsert_Bulk33 'QER-K-ShoppingRackPWOHelperPWO', @DBQueueElements_01 end  if update(UID_Department) or update(UID_ProfitCenter) begin if @PWOTaskToUse > ' ' begin declare34 @DBQueueElements_02 QBM_YDBQueueRaw insert into @DBQueueElements_02 (object, subobject, genprocid) select x.uid, null, @GenProcID from (select d.UID_PersonWantsOrg35 as uid from deleted d join PersonWantsOrg pwo on d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg where isnull(d.UID_Department, '') <> isnull(pwo.UID_Department36, '') or isnull(d.UID_ProfitCenter, '') <> isnull(pwo.UID_ProfitCenter, '') ) as x  exec QBM_PDBQueueInsert_Bulk @PWOTaskToUse, @DBQueueElements_02 end37  end  if update(OrderState) begin  declare @DBQueueElements_03 QBM_YDBQueueRaw insert into @DBQueueElements_03 (object, subobject, genprocid) select x.uid38, null, @GenProcID from (select pwo.UID_PersonWantsOrg as uid from deleted d join personwantsorg pwo on d.uid_personwantsorg = pwo.uid_Personwantsorg  39  where d.OrderState in ('Assigned', 'OrderProlongate', 'OrderUnsubscribe' ) and pwo.OrderState in ('Aborted', 'Dismissed', 'Unsubscribed' ) ) as x exec40 QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackCheckWaiting', @DBQueueElements_03  declare @DBQueueElements_04 QBM_YDBQueueRaw insert into @DBQueueElements_0441 (object, subobject, genprocid) select x.uid, null, @GenProcID from (select pwo.UID_PersonWantsOrg as uid from deleted d join personwantsorg pwo on d.uid_PersonWantsOrg42 = pwo.uid_PersonWantsOrg   join QER_VPWOPersonPropertyReset r on pwo.UID_PersonWantsOrg = r.UID_PersonWantsOrg where d.OrderState in ('Assigned', 'Granted'43, 'New', 'OrderProduct', 'OrderProlongate', 'OrderUnsubscribe', 'Waiting') ) as x exec QBM_PDBQueueInsert_Bulk 'QER-K-ITShopRepairClosed', @DBQueueElements_0444  insert into @PWOsAreFinished(Parameter1) select pwo.uid_personwantsorg from personwantsorg pwo join deleted d on pwo.uid_Personwantsorg = d.uid_personwantsorg45    where pwo.OrderState in ('Aborted', 'Assigned', 'Dismissed', 'Granted', 'New', 'Unsubscribed', 'Waiting') and d.OrderState in ('OrderProduct', 'OrderProlongate'46, 'OrderUnsubscribe') select @CountPWOsAreFinished = @@ROWCOUNT  declare @DBQueueElements_05 QBM_YDBQueueRaw insert into @DBQueueElements_05 (object, subobject47, genprocid) select x.uid, null, @GenProcID from (select d.UID_PersonWantsOrg as uid from deleted d join PersonWantsOrg pwo on d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg48  left outer join @PWOsAreFinished fi on fi.Parameter1 = d.UID_PersonWantsOrg where isnull(d.OrderState, '') <> isnull(pwo.OrderState, '') and fi.Parameter149 is null ) as x  exec QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackPWOHelperPWO', @DBQueueElements_05  insert into @PWOsToResetGenProcID(Parameter1) select50 pwo.uid_personwantsorg from personwantsorg pwo join deleted d on pwo.uid_Personwantsorg = d.uid_personwantsorg  where pwo.OrderState in ('Aborted', 'Assigned'51, 'Dismissed', 'Unsubscribed') and d.OrderState in ('OrderProduct', 'OrderProlongate', 'OrderUnsubscribe', 'Granted', 'New', 'Waiting') select @CountPWOsToResetGenProcID52 = @@ROWCOUNT if @CountPWOsAreFinished > 0 begin  insert into @PWOHelperPWOToDeleteLater(Parameter1) select  h.XObjectKey  from PWOHelperPWO h with (readpast53) where uid_Personwantsorg in ( select Parameter1 from @PWOsAreFinished ) if @@ROWCOUNT > 0 begin exec QBM_PJobCreate_SQLDel_L 'PWOHelperPWO', @PWOHelperPWOToDeleteLater54 , @GenProcID = @GenProcID , @AdditionalObjectKeysAffected = default , @Retries = 5 , @isToFreezeOnError = 1 end  if exists (select top 1 1 from HelperPWOPersonHasObject55 h with (readpast) join @PWOsAreFinished f on h.UID_PersonWantsOrg = f.Parameter1 ) begin select @DeleteWhereClause = 'UID_PersonWantsOrg in ' + dbo.QBM_FCVParameter1AsOneInClause56(@PWOsAreFinished) exec QBM_PJobCreate_SQLDel_B 'HelperPWOPersonHasObject' , @whereclause = @DeleteWhereClause , @GenProcID = @GenProcID , @AdditionalObjectKeysAffected57 = default , @isToFreezeOnError = 1 , @Retries = 5 end  if exists (select top 1 1 from HelperPWOCompliance h with (readpast) join @PWOsAreFinished f on58 h.UID_PersonWantsOrg = f.Parameter1 ) begin select @DeleteWhereClause = 'UID_PersonWantsOrg in ' + dbo.QBM_FCVParameter1AsOneInClause(@PWOsAreFinished59) exec QBM_PJobCreate_SQLDel_B 'HelperPWOCompliance' , @whereclause = @DeleteWhereClause , @GenProcID = @GenProcID , @AdditionalObjectKeysAffected = default60 , @isToFreezeOnError = 1 , @Retries = 5 end  end  if @CountPWOsToResetGenProcID > 0 begin update PersonWantsOrg set GenProcID = null  , XDateUpdated =61 @Xdate , XUserUpdated = @XUser where uid_Personwantsorg in ( select Parameter1 from @PWOsToResetGenProcID ) end   end  if update(DecisionLevel) or update62(OrderState)  or update(UID_PersonInserted) or update(UID_PersonOrdered) begin  delete  @PWOBuffer insert into @PWOBuffer(UID1 , Bit1 , int1 , Int2  ) 63select pwo.uid_personwantsorg  , case  when isnull(d.DecisionLevel,0) <> isnull(pwo.DecisionLevel, 0) then 1  when d.OrderState not in ( 'OrderProlongate'64 , 'OrderUnsubscribe') and pwo.OrderState in ( 'OrderProlongate' , 'OrderUnsubscribe') then 1 else 0 end as isNewDecisionLevel  , pwo.DecisionLevel   ,65 case when d.OrderState not in ( 'OrderProlongate' , 'OrderUnsubscribe') and pwo.OrderState in ( 'OrderProlongate' , 'OrderUnsubscribe') then 1 else 0 66end as IsOrderStarted  from deleted d join Personwantsorg pwo on d.uid_personwantsorg = pwo.uid_personwantsorg  left outer join @PWOsAreFinished fi on 67fi.Parameter1 = d.UID_PersonWantsOrg where d.DecisionLevel <> pwo.DecisionLevel and fi.Parameter1 is null   or pwo.OrderState in ('OrderProduct', 'OrderProlongate'68, 'OrderUnsubscribe')  select @ElementCount = @@ROWCOUNT select @ElementIndex = @@IDENTITY - @ElementCount +1 select @ElementLast = @@IDENTITY while @ElementIndex69 <= @ElementLast begin select top 1 @uid_Personwantsorg = bu.UID1  , @isNewDecisionLevel = bu.bit1  , @newDecisionLevel = bu.int1  , @IsOrderStarted = 70sign(bu.Int2)  from @PWOBuffer bu where bu.ElementIndex = @ElementIndex if @isNewDecisionLevel = 1 begin   exec QER_PITShopOrderResetOneLevel @uid_personwantsorg71, @newDecisionLevel, @GenProcID end select @ElementIndex += 1 end   insert into @PWOsToFillHelper(Parameter1, Parameter2, Parameter3, HasContentFull) select72 bu.UID1 as UID_PersonwantsOrg , @GenProcID  , '1' as CurrentLevelOnly , bu.bit1 as IsNewDecisionLevel from @PWOBuffer bu where (sign(bu.Int2)  = 1 and73 @DecisionOnInsert = 1 or sign(bu.Int2)  = 0 ) and not exists (select top 1 1 from @PWOsToFillHelper e where e.Parameter1 = bu.UID1 )  declare @DBQueueElements_0674 QBM_YDBQueueRaw insert into @DBQueueElements_06 (object, subobject, genprocid) select x.uid, null, @GenProcID from (select i.UID_PersonWantsOrg as uid75 from inserted i  left outer join @PWOsAreFinished fi on fi.Parameter1 = i.UID_PersonWantsOrg where fi.Parameter1 is null ) as x  exec QBM_PDBQueueInsert_Bulk76 'QER-K-ShoppingRackPWOHelperPWO', @DBQueueElements_06 exec QBM_PDBQueueInsert_Bulk 'QER-K-ShoppingRackCheckDecision', @DBQueueElements_06  end  if update77(OrderState) or update(DecisionLevel) begin  insert into @PWOHelperPWOToDeleteImmediate(Parameter1) select h.UID_PWOHelperPWO from PWOHelperPWO h with 78(readpast) join inserted i on i.uid_PersonWantsOrg = h.uid_PersonWantsOrg  left outer join @PWOsAreFinished fi on fi.Parameter1 = i.UID_PersonWantsOrg 79where UID_PWODecisionRule = 'QER-PWODecisionRule-QP' and fi.Parameter1 is null end if update(isReserved) begin   insert into @PWOHelperPWOToDeleteImmediate80(Parameter1) select h.UID_PWOHelperPWO from PWOHelperPWO h with (readpast)  left outer join @PWOsAreFinished fi on fi.Parameter1 = h.UID_PersonWantsOrg81 where h.UID_PWODecisionRule = 'QER-PWODecisionRule-QP' and fi.Parameter1 is null and exists (select top 1 1 from deleted d join personwantsorg pwo on 82d.uid_PersonWantsOrg = pwo.uid_PersonWantsOrg and d.isreserved = 1 and pwo.isReserved = 0 where pwo.UID_PersonWantsOrg = h.UID_PersonWantsOrg ) end if 83exists (select top 1 1 from @PWOHelperPWOToDeleteImmediate ) begin delete PWOHelperPWO from PWOHelperPWO h where h.UID_PWOHelperPWO in (select d.Parameter184 from @PWOHelperPWOToDeleteImmediate d ) end if exists (select top 1 1 from @PWOsToFillHelper h join @PWOsAreFinished fi on h.Parameter1 = fi.Parameter185 ) begin delete @PWOsToFillHelper where Parameter1 in (select Parameter1 from @PWOsAreFinished) end  if exists (select top 1 1 from @PWOsToFillHelper )86 begin  if @DecisionOnInsert = 1 begin  declare @PWOsToFire QBM_YParameterList  insert into @PWOsToFire(Parameter1) select pwo.XObjectKey from @PWOsToFillHelper87 i join PersonWantsOrg pwo on i.Parameter1 = pwo.UID_PersonWantsOrg join deleted d on d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg where pwo.OrderState88 in ('OrderProlongate', 'OrderUnsubscribe') and d.OrderState not in ('OrderProlongate', 'OrderUnsubscribe') exec QBM_PJobCreate_HOCallMethod_L @objecttype89 = 'PersonWantsOrg' , @XObjectKeys = @PWOsToFire  , @save = 1 , @MethodName = 'MakeDecisionOnInsertAsync' , @GenProcID = @GenProcID , @AdditionalObjectKeysAffected90 = default , @Retries = 3 , @isToFreezeOnError = 1 , @WhereClauseAdditional = 'DecisionLevel = 0 and OrderState in (''OrderProlongate'', ''OrderUnsubscribe'')'91 , @checkForExisting = 1  delete @PWOsToFillHelper from @PWOsToFillHelper i join PersonWantsOrg pwo on i.Parameter1 = pwo.UID_PersonWantsOrg join deleted92 d on d.UID_PersonWantsOrg = pwo.UID_PersonWantsOrg where pwo.OrderState in ('OrderProlongate', 'OrderUnsubscribe') and d.OrderState not in ('OrderProlongate'93, 'OrderUnsubscribe')  end  exec QER_PITShopHelperFill_bulk @PWOsToFillHelper end if exists (select top 1 1 from @PWOsToFillHasObject ) begin exec QER_PITShopPersonHasObjFill_b94 @PWOsToFillHasObject, @IsCalledFromTrigger = 0  end  if update(OrderState) or update(UID_PersonHead) or update(UID_PersonOrdered) or update(UID_PersonInserted95) begin delete  @CursorBuffer insert into @CursorBuffer(UID1, ObjectKey1, UID2) select pwo.uid_personwantsorg, pwo.XObjectKey , dbo.QER_FGIGenProcIDForPWO96(pwo.GenProcID, @GenProcID, @CfgUseGenProcID) as GenProcID from deleted d join PersonWantsOrg pwo on pwo.UID_PersonWantsOrg = d.UID_PersonWantsOrg     97 and pwo.OrderState in ('Assigned', 'Granted', 'New', 'OrderProduct', 'OrderProlongate', 'OrderUnsubscribe', 'Waiting') join Delegation de on pwo.UID_PersonWantsOrg98 = de.UID_PersonWantsOrg left outer join Person p1 on de.UID_PersonSender = p1.UID_Person left outer join Person p2 on de.UID_PersonReceiver = p2.UID_Person99 where p1.UID_Person is null or p2.UID_Person is null select @ElementCount = @@ROWCOUNT select @ElementIndex = @@IDENTITY - @ElementCount +1 select @ElementLast100 = @@IDENTITY while @ElementIndex <= @ElementLast begin select top 1 @uid_personwantsorg = bu.UID1 , @BasisObjectKey = bu.ObjectKey1 ,@GenProcIDToUse =101 bu.UID2 from @CursorBuffer bu where bu.ElementIndex = @ElementIndex select @SQLcmd = N'uid_personwantsorg = ''' + rtrim(@uid_personwantsorg) + N'''' select102 @UID_PWOStateFinalError = dbo.QER_FGIPWOStateFinalError(@UID_PersonWantsOrg) exec QBM_PJobCreate_HOCallMethod @objecttype = 'personwantsorg' , @whereclause103 = @SQLcmd , @save = 1 , @MethodName = 'Abort' , @GenProcID = @GenProcIDToUse , @ObjectKeysAffected = default , @param1 = '#LDS#Closing delegation because its source was deleted.|'104 , @param2 = @UID_PWOStateFinalError , @Retries = 3 , @isToFreezeOnError = 1 , @BasisObjectKey = @BasisObjectKey , @checkForExisting = 1  , @WhereClauseAdditional105 = ' OrderState in (''Assigned'', ''Granted'', ''New'', ''OrderProduct'', ''OrderProlongate'', ''OrderUnsubscribe'', ''Waiting'')'  select @ElementIndex106 += 1 end   end  END TRY BEGIN CATCH exec QBM_PSessionErrorAdd default RAISERROR ('', 18, 1) WITH NOWAIT END CATCH ende: return end 107