# mes.spGetProductionDataForReliability

## Description
This stored procedure collects detailed production and reliability data for a given asset and mode across a defined time range. It calculates raw counters, availability, performance, and quality metrics, including takt time, actual rates, and loss analyses, suitable for reliability and performance dashboards.

## Syntax
<b>mes.spGetProductionDataForReliability @assetId, @rangeStart, @rangeEnd, @modeId</b><br /><br />

<b>Parameters:</b><br />
@assetId (int): The ID of the asset<br />
@rangeStart (datetime): Start timestamp for the query (optional)<br />
@rangeEnd (datetime): End timestamp for the query (optional)<br />
@modeId (int): Mode identifier to filter production context<br /><br />

<b>Returns:</b><br />
Each row represents a production period and includes:<br />
- Asset and mode metadata<br />
- Item and work order references<br />
- Duration (in seconds)<br />
- Runtime, downtime, and planned downtime in seconds<br />
- Counter metrics: infeedCount, outfeedCount, wasteCount<br />
- TargetCount and taktTime<br />
- Calculated metrics:
  - **Availability**
  - **Performance**
  - **Quality**
  - **Infeed rate per second**
  - **Actual production rate**
  - **Lossed units and performance loss seconds**
  - **Quality loss seconds**

### Code Example

```sql
EXEC mes.spGetProductionDataForReliability
    @assetId = 1001,
    @rangeStart = '2025-07-01',
    @rangeEnd = '2025-07-10',
    @modeId = 2;
