# mes.fnGetRunTimesAndCounts

## Description
Returns runtime, downtime, and counter totals for a given asset within a time range.

## Syntax
  <b>mes.fnGetRunTimesAndCounts(@assetId, @startDate, @endDate)</b>  
  <br /><br />
  <b>Parameters:</b><br />
  <li>@assetId (int): Asset Id</li>
  <li>@startDate (datetime): Start of the time range</li>
  <li>@endDate (datetime): End of the time range</li>
  <br />
  <b>Returns:</b><br />
  <div>Returns a table with columns:</div>
    <li>runtimeSecs (int): Running time in seconds</li>
    <li>unplannedDowntimeSecs (int): Unplanned downtime in seconds</li>
    <li>plannedDowntimeSecs (int): Planned downtime in seconds</li>
    <li>rawInfeedCount (float): Total infeed count</li>
    <li>rawOutfeedCount (float): Total outfeed count</li>
    <li>rawWasteCount (float): Total waste count</li>

### Code Example
```sql
-- Get production runtime and counts summary
SELECT *
FROM mes.fnGetRunTimesAndCounts(2076, '2025-07-01T00:00:00', '2025-07-30T23:59:59');
