Skip to main content

mes.fnGetStateSeconds

Description

Returns total duration in seconds for a given state type within a time range for an asset.

Syntax

mes.fnGetStateSeconds(@assetId, @rangeStart, @rangeEnd, @stateTypeId)

Parameters:
  • @assetId (int): Asset Id
  • @rangeStart (datetime): Start of the time range
  • @rangeEnd (datetime): End of the time range
  • @stateTypeId (int): State type Id

  • Returns:
  • int: Total seconds in the specified state
  • Code Example

    SELECT mes.fnGetStateSeconds(
    2076,
    '2025-07-30T00:00:00',
    '2025-07-30T12:00:00',
    2
    ) AS seconds_in_state;