mes.spGetAssetStateEventByCategory
Description
Retrieves state event durations for a specific asset, grouped by state category and type, within a given time range. Filters allow for selecting events based on duration, changed states, or only downtime-related states.Syntax
mes.spGetAssetStateEventByCategory @assetId, @rangeStart, @rangeEnd, @durationSecs, @showChanged, @showDowntimeOnlyParameters:
@assetId (int): The ID of the asset to analyze.
@rangeStart (datetime): Start of the time range.
@rangeEnd (datetime): End of the time range.
@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 include only downtime-related state events (1 = include only downtime, 0 = include all).
Returns:
- assetPath: Full path of the asset in the hierarchy.
- assetName: Name of the asset.
- assetId: The ID of the asset.
- stateCategoryName: Category of the state (or "No Category" if undefined).
- stateTypeName: Logical type of the state (e.g., Running, Planned Downtime).
- stateTypeColor: Color associated with the state type.
- durationSecs: Total seconds the asset spent in that state category/type.
Code Example
-- Get categorized state event summary for asset 1005 during July 2025
EXEC mes.spGetAssetStateEventByCategory
@assetId = 1005,
@rangeStart = '2025-07-01',
@rangeEnd = '2025-07-31',
@durationSecs = 60,
@showChanged = 1,
@showDowntimeOnly = 0;