SQL-007: Retrieve pending premium audits for a processing window¶
This is the queue read that starts every premium audit batch run. The scheduled
job resolves its processing window from configuration, then calls
dbo.usp_GetPendingAudits to obtain the set of audits whose due date falls in
that window and whose status has not yet advanced past Pending. The optional
@PolicyNumber argument supports the operator-initiated single-policy rerun
described in the operational runbook; when it is omitted the procedure returns
the full window. Rows are returned ordered by due date so that the oldest
backlog is worked first, and the procedure applies its own NOLOCK-free read
because the queue table is written concurrently by the policy system.
-- Stored procedure call issued by PendingAuditRepository.GetPendingAuditsEXECdbo.usp_GetPendingAudits@AuditPeriodStart=@AuditPeriodStart,@AuditPeriodEnd=@AuditPeriodEnd,@PolicyNumber=@PolicyNumber-- Procedure body resides in the SQL Server database and is version-controlled-- in db/Procedures/usp_GetPendingAudits.sql
-- Procedure body, from db/Procedures/usp_GetPendingAudits.sqlSELECTq.AuditQueueId,q.PolicyNumber,q.AuditDueDate,q.AuditStatusCode,q.AttemptCount,p.PolicyEffectiveDate,p.PolicyExpirationDate,p.ServicingBranchCode,s.AuditStatusNameFROMdbo.PremiumAuditQueueASqINNERJOINdbo.PolicyASpONp.PolicyNumber=q.PolicyNumberINNERJOINdbo.AuditStatusASsONs.AuditStatusCode=q.AuditStatusCodeWHEREq.AuditDueDate>=@AuditPeriodStartANDq.AuditDueDate<=@AuditPeriodEndANDs.IsTerminal=0ANDq.LockedByProcessISNULLAND(@PolicyNumberISNULLORq.PolicyNumber=@PolicyNumber)ORDERBYq.AuditDueDateASC,q.AuditQueueIdASC