---
title: "SQL-008: Insert IMAGE_AGENCY row (conditional)"
summary: Conditionally inserts a row into IMAGE_AGENCY linking an indexed image to an agency, when IMAGE_FILE_CODE = "AGNCY".
status: draft
owner: <owner>
last_reviewed: 2026-07-24
library: SAIF.Business.Imaging
reference_type: package
---

# SQL-008: Insert IMAGE_AGENCY row (conditional)

This statement is conditionally executed during `clsImageIdx.BeforeInsert` as a secondary data request (`DR2`) when `IMAGE_FILE_CODE = "AGNCY"`. It creates an `IMAGE_AGENCY` sub-record linking the image to the specified agency.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-008 |
| **Operation type** | Create |
| **Execution method** | Inline SQL |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | Text** |
| **Business object** | `clsImageIdx` |
| **Criteria property** | `InsertImageAgencySQL` |
| **Lifecycle method** | `BeforeInsert (conditional DR2)` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:ImageSeqNum` | Input | [not specified]** | N/A | Foreign key to the IMAGE row. |
| `:AgencyId` | Input | [not specified]** | N/A | The agency sequence number to associate with the image. |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [IMAGE_AGENCY](../database-tables.md#image_agency) | INSERT | IMAGE_AGENCY_SEQ_NUM, IMAGE_SEQ_NUM, AGENCY_SEQ_NUM |

## Sample SQL

```sql
Insert into IMAGE_AGENCY (
    IMAGE_AGENCY_SEQ_NUM,
    IMAGE_SEQ_NUM,
    AGENCY_SEQ_NUM
) Values (
    IMAGE_AGENCY_SEQ.NEXTVAL,
    :ImageSeqNum,
    :AgencyId
)
```

## Operations and processes
- [Image indexing](../operations/image-indexing.md)

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

## Sources
- `Business\SAIF.Business.Imaging\clsImageIdx.vb`
