---
title: "SQL-223: ReserveQueryProvider.GetIncurredCostForDate"
summary: Read operation for `ReserveQueryProvider.GetIncurredCostForDate`
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data
reference_type: package
---

# SQL-223: ReserveQueryProvider.GetIncurredCostForDate

This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by `ReserveQueryProvider.GetIncurredCostForDate`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-223 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Oracle* |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `ReserveQueryProvider` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `GetIncurredCostForDate` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `claimId` | Input | long | N/A | Method argument of `ReserveQueryProvider.GetIncurredCostForDate` bound into the ORM expression; NHibernate generates the bind variable at runtime |
| `effectiveDate` | Input | DateTime | N/A | Method argument of `ReserveQueryProvider.GetIncurredCostForDate` bound into the ORM expression; NHibernate generates the bind variable at runtime |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [CL_INCURRED_COST_HISTORY](../database-tables.md#cl_incurred_cost_history) | SELECT (outer + correlated subquery) | CL_INCURRED_COST_HIST_SEQ_NUM, UPDATE_NUM, CLAIM_COST_DATE, RESERVE_APPROVER_USER, RESERVE_INITIATOR_USER, GENERAL_ANALYSIS_TEXT, UPDATE_DATE, UPDATE_USER, CLAIM_ID |

## LINQ statement

Source: `Data/SAIF.Data/Queries/Claims/ReserveQueryProvider.cs:31-35`. The repository/queryable is initialised at `Data/SAIF.Data/Queries/Claims/ReserveQueryProvider.cs:17`.

```csharp
// Data/SAIF.Data/Queries/Claims/ReserveQueryProvider.cs:17
repository = Factory.GetRepository<IncurredCostHistory>().Query();

// Data/SAIF.Data/Queries/Claims/ReserveQueryProvider.cs:31-35
public IncurredCostHistory GetIncurredCostForDate(long claimId, DateTime effectiveDate)
{
    return repository.Where(w => w.Claim.Id == claimId)
              .SingleOrDefault(x => x.Id == repository
                      .Where(w => w.Claim.Id == claimId
                      && effectiveDate >= x.ClaimCostDate.Date
                      && effectiveDate <= x.ClaimCostDate.Date).Max(m => m.Id));
}
```

## Sample SQL

> **Inferred SQL:** This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT
  CICH.CL_INCURRED_COST_HIST_SEQ_NUM,
  CICH.UPDATE_NUM,
  CICH.CLAIM_COST_DATE,
  CICH.RESERVE_APPROVER_USER,
  CICH.RESERVE_INITIATOR_USER,
  CICH.GENERAL_ANALYSIS_TEXT,
  CICH.UPDATE_DATE,
  CICH.UPDATE_USER,
  CICH.CLAIM_ID
FROM CL_INCURRED_COST_HISTORY CICH
WHERE CICH.CLAIM_ID = :claimId
  AND CICH.CL_INCURRED_COST_HIST_SEQ_NUM = (
    SELECT MAX(CICH2.CL_INCURRED_COST_HIST_SEQ_NUM)
    FROM CL_INCURRED_COST_HISTORY CICH2
    WHERE CICH2.CLAIM_ID = :claimId
      AND :effectiveDate >= TRUNC(CICH.CLAIM_COST_DATE)
      AND :effectiveDate <= TRUNC(CICH.CLAIM_COST_DATE)
  )
-- SingleOrDefault: NHibernate expects at most one row
```

Translation notes:
- **Correlation to the outer row.** The date predicates inside the subquery reference `x.ClaimCostDate`, where `x` is the *outer* `SingleOrDefault` parameter, not `w`. They therefore correlate to the outer alias `CICH`. As written, the query returns the claim's latest row only if that row's truncated `CLAIM_COST_DATE` equals `:effectiveDate`; it does not return the latest row *on* that date. This looks like a source defect (intended `w.ClaimCostDate`), translated faithfully.
- `ClaimCostDate.Date` → Oracle `TRUNC(col)`. If `:effectiveDate` carries a time component, the `>=`/`<=` pair can never both hold.

## Operations and processes

- [Other query providers](../operations/other-query-providers.md)


## Sources
- `Data/SAIF.Data/Queries/Claims/ReserveQueryProvider.cs:31`
