Skip to main content

mes.spGetAssetStateEvents

Description

Retrieves raw asset state event data by invoking the internal table-valued function `fnGetAssetStateEvents`. Includes adjusted start time logic to include state changes that begin prior to the selected time window.

Syntax

mes.spGetAssetStateEvents @assetId, @rangeStart, @rangeEnd, @durationSecs, @showChanged, @showDowntimeOnly

Parameters:
@assetId (int): ID of the asset to evaluate.
@rangeStart (datetime): Start of the time window.
@rangeEnd (datetime): End of the time window. Future dates are truncated to current time.
@durationSecs (int): Minimum duration (in seconds) for a state event to be included.
@showChanged (bit): Whether to include changed state events (1 = include, 0 = exclude).
@showDowntimeOnly (bit): Whether to restrict results to only downtime events (1 = yes, 0 = no).

Returns:
Full result set from fnGetAssetStateEvents, including detailed columns like:
- assetId
- assetPath
- assetName
- stateCode
- stateName
- stateCategoryName
- stateTypeName
- startDate, endDate
- stateDurationSecs, stateDurationMins
... and more.

Code Example

-- Retrieve detailed state events for asset 3055 in July 2025
EXEC mes.spGetAssetStateEvents
@assetId = 3055,
@rangeStart = '2025-07-01',
@rangeEnd = '2025-07-31',
@durationSecs = 60,
@showChanged = 1,
@showDowntimeOnly = 0;