# mes.spGetOEEDataByIntervalByShift

## Description
Calculates Overall Equipment Effectiveness (OEE) metrics for a given asset across shifts, aligned to time-based intervals (Hour, Day, or Week). Aggregates runtime, downtime, and counter metrics using shift windows. Ideal for tracking OEE by operational shifts.

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

<b>Parameters:</b><br />
@assetId (int): Asset ID to analyze.<br />
@startDate, @endDate (datetime): Time range for calculation.<br />
@interval (varchar): Interval granularity. One of 'Hour', 'Day', or 'Week'.<br /><br />

<b>Returns:</b><br />
List of shift-level rows with:<br />
- Shift ID, name, asset and item metadata<br />
- Duration, runtime, planned and unplanned downtime<br />
- Counter-based performance and quality<br />
- Computed OEE KPIs (availability, performance, quality, oee)

### Code Example

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