---
title: "SQL-005: Retrieve correspondence by sequence number"
summary: Inline read that loads one correspondence row by ENDORSE_SEQ_NUM.
status: draft
owner: Technical Writer
last_reviewed: 2026-07-31
library: SAIF.Business.Policy.Correspondence
reference_type: package
---

# SQL-005: Retrieve correspondence by sequence number

This read path retrieves a single correspondence record when the caller already knows the correspondence sequence number. The correlated subquery reads `OUTPUT_LOG` to project the highest non-zero image sequence number onto the business object.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-005 |
| **Operation type** | Read |
| **Execution method** | Inline SQL |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | Text |
| **Business object** | `clsCorrespondence` |
| **Criteria property** | `RetrieveSQL` |
| **Lifecycle method** | `BeforeRetrieve` / `AfterRetrieve` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| :CorrespondenceSequenceNumber | Input | Decimal (NUMBER) | — | ENDORSEMENT primary key. |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [ENDORSEMENT](../database-tables.md#endorsement) | SELECT | full correspondence column projection |
| [OUTPUT_LOG](../database-tables.md#output_log) | SELECT | IMAGE_SEQ_NUM, POLICY_NUM, CORRESPOND_SEQ_NUM |

## Sample SQL

```sql
SELECT
  E.POLICY_NUM AS PolicyNumber,
  E.POLICY_PERIOD_EFF_DATE AS PolicyPeriodEffectiveDate,
  E.ENDORSE_SEQ_NUM AS CorrespondenceSequenceNumber,
  E.EFFECTIVE_DATE AS EffectiveDate,
  E.EXPIRATION_DATE AS ExpirationDate,
  E.ENDORSE_DATE AS CorrespondenceDate,
  E.PRINTED_DATE AS PrintedDate,
  E.ENDORSE_CODE AS CorrespondenceCode,
  E.NEW_VALUE AS NewValue,
  E.OLD_VALUE AS OldValue,
  E.CREATE_USER AS CreateUser,
  E.CREATE_DATE AS CreateDate,
  E.HOLD_PRINT_FLAG AS HoldPrintFlag,
  E.CORR_JOBID AS CorrespondenceJobID,
  E.UPDATE_USER AS UpdateUser,
  E.UPDATE_DATE AS UpdateDate,
  E.VERSION_CODE AS VersionCode,
  E.PRINTED_NCCI_CODE AS NCCIEndorsementCode,
  E.CANCEL_ENDORSE_SEQ_NUM AS CancelEndorseSequenceNumber,
  (SELECT MAX(image_seq_num)
     FROM output_log ol
    WHERE NVL(ol.image_seq_num, 0) > 0
      AND ol.policy_num = e.POLICY_NUM
      AND ol.correspond_seq_num = e.ENDORSE_SEQ_NUM) AS ImageSeqNum
FROM ENDORSEMENT E
WHERE E.ENDORSE_SEQ_NUM = :CorrespondenceSequenceNumber
```

## Operations and processes
- [Retrieve a correspondence item](../operations/retrieve-a-correspondence-item.md)

## Business rules
- [BR-008: Correspondence retrieval switches between two key shapes](../business-rules.md#br-008-correspondence-retrieval-switches-between-two-key-shapes)



> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `Business\SAIF.Business.Policy.Correspondence\clsCorrespondence.vb`
