---
title: "SQL-011: clsXDocumentCollection.RetrieveSQL"
summary: Retrieves documents for a print-control batch with printer/bin routing join (ByDocSeq mode).
status: draft
owner: <owner>
last_reviewed: 2026-07-24
library: SAIF.Services.Printing.Remote
reference_type: package
---

# SQL-011: clsXDocumentCollection.RetrieveSQL

Retrieves all documents in a print-control batch by joining `XDOCUMENT`, `XPRINTER_BIN`, and `XPRINTER` to resolve the physical bin number and printer network name for a given `XPrintControlSeqNum` and `PrinterID`. Results are ordered by the ten sort-value columns for print sequencing. Used when `PrintType = ByDocSeq`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-011 |
| **Operation type** | Read (Retrieve) |
| **Execution method** | Inline |
| **Database** | Oracle |
| **Schema** | `[unqualified]**` |
| **Command type** | Text |
| **Business object** | `clsXDocumentCollection` |
| **Criteria property** | `RetrieveSQL` |
| **Lifecycle method** | `BeforeRetrieve` (`PrintType = ByDocSeq`) |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:XPrintControlSeqNum` | Input | Decimal | — | FK filter — batch header whose documents are being retrieved |
| `:PrinterID` | Input | String | 30 | Printer identifier used to resolve bin/printer routing via `XPRINTER_BIN`/`XPRINTER` join |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [XDOCUMENT](../database-tables.md#xdocument) | SELECT | `COPIES_COUNT`, `DOCUMENT_TYPE_CODE`, `EMAIL_ADDRESS`, `FAX_NUM`, `FILE_NAME`, `IDX_CONTENTS_TEXT`, `SORT0_VALUE`–`SORT9_VALUE`, `START_VALUE`, `XBIN_TYPE_CODE`, `XDOCUMENT_SEQ_NUM`, `XPRINT_CONTROL_SEQ_NUM`, `DUPLEX_CODE` |
| [XPRINTER_BIN](../database-tables.md#xprinter_bin) | JOIN | `PRINTER_ID`, `XBIN_TYPE_CODE`, `BIN_NUM` |
| [XPRINTER](../database-tables.md#xprinter) | JOIN | `PRINTER_ID`, `NETWORK_NAME` |

## Sample SQL

```sql
Select
    XDOCUMENT.COPIES_COUNT              as CopiesCount,
    XDOCUMENT.DOCUMENT_TYPE_CODE        as DocumentTypeCode,
    XDOCUMENT.EMAIL_ADDRESS             as EmailAddress,
    XDOCUMENT.FAX_NUM                   as FaxNum,
    XDOCUMENT.FILE_NAME                 as FileName,
    XDOCUMENT.IDX_CONTENTS_TEXT         as IdxContentsText,
    XDOCUMENT.SORT0_VALUE               as Sort0Value,
    XDOCUMENT.SORT1_VALUE               as Sort1Value,
    XDOCUMENT.SORT2_VALUE               as Sort2Value,
    XDOCUMENT.SORT3_VALUE               as Sort3Value,
    XDOCUMENT.SORT4_VALUE               as Sort4Value,
    XDOCUMENT.SORT5_VALUE               as Sort5Value,
    XDOCUMENT.SORT6_VALUE               as Sort6Value,
    XDOCUMENT.SORT7_VALUE               as Sort7Value,
    XDOCUMENT.SORT8_VALUE               as Sort8Value,
    XDOCUMENT.SORT9_VALUE               as Sort9Value,
    XDOCUMENT.START_VALUE               as StartValue,
    XDOCUMENT.XBIN_TYPE_CODE            as XBinTypeCode,
    XDOCUMENT.XDOCUMENT_SEQ_NUM         as XDocumentSeqNum,
    XDOCUMENT.XPRINT_CONTROL_SEQ_NUM    as XPrintControlSeqNum,
    XPRINTER_BIN.BIN_NUM                as XBinNumber,
    XPRINTER.NETWORK_NAME               as PrinterNetworkName,
    XDOCUMENT.DUPLEX_CODE               as DuplexCode
From
    XDOCUMENT, XPRINTER_BIN, XPRINTER
Where
    XDOCUMENT.XPRINT_CONTROL_SEQ_NUM = :XPrintControlSeqNum
    AND XPRINTER_BIN.PRINTER_ID = :PrinterID
    AND XPRINTER_BIN.PRINTER_ID = XPRINTER.PRINTER_ID
    AND XDOCUMENT.XBIN_TYPE_CODE = XPRINTER_BIN.XBIN_TYPE_CODE
ORDER BY
    XDOCUMENT.SORT0_VALUE,
    XDOCUMENT.SORT1_VALUE,
    XDOCUMENT.SORT2_VALUE,
    XDOCUMENT.SORT3_VALUE,
    XDOCUMENT.SORT4_VALUE,
    XDOCUMENT.SORT5_VALUE,
    XDOCUMENT.SORT6_VALUE,
    XDOCUMENT.SORT7_VALUE,
    XDOCUMENT.SORT8_VALUE,
    XDOCUMENT.SORT9_VALUE
```

## Operations and processes
- [Retrieve documents for printing](../operations/retrieve-documents-for-printing.md)

## Business rules
- [BR-004: Duplex mode controlled vocabulary](../business-rules.md#br-004-duplex-mode-controlled-vocabulary)

> **Note:** Statements marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- `Services\SAIF.Services.Printing.Remote\clsXDocumentCollection.vb`
