# mes.spGetOEEDataByInterval

## Description
Generates OEE (Overall Equipment Effectiveness) and supporting metrics for an asset over a time range, aggregated by hour/day/week. Utilizes run states, counters, and mode data to derive KPIs. Performs dynamic interval grouping using recursive CTEs.

## Syntax
<b>mes.spGetOEEDataByInterval @assetId, @startDate, @endDate, @interval</b>  
<br /><br />

<b>Parameters:</b><br />
@assetId (int): ID of the asset to analyze.<br />
@startDate, @endDate (datetime): Time window for analysis.<br />
@interval (varchar): One of 'Hour', 'Day', or 'Week'.<br /><br />

<b>Returns:</b><br />
List of OEE intervals with:<br />
- Runtime, downtime, production counts<br />
- Item metadata and standard rate<br />
- Cross-applied `fnGetOEEMetrics` values

### Code Example

```sql
EXEC mes.spGetOEEDataByInterval
    @assetId = 1024,
    @startDate = '2025-07-01',
    @endDate = '2025-07-10',
    @interval = 'Day';
