Querying the StateSummaryHistory view
- Last UpdatedMar 20, 2025
- 1 minute read
The StateSummaryHistory view is a "wide" view that allows you to return multiple statistics for a single tag within a single query.
The following query returns the state count, total time in state, and the percentage of time in state for the SysPulse system tag for the last hour. One row is returned for each state.
DECLARE @End DateTime
SET @END = getdate()
SELECT
TagName,
Value,
OPCQuality,
StateCount,
StateTimeTotal,
StateTimePercent
FROM dbo.StateSummaryHistory
WHERE TagName = N'SysPulse'
AND StartDateTime >= dateadd(minute,-60,@End)
AND EndDateTime <= @End
AND wwCycleCount = 1
The results are:
|
TagName |
Value |
OPCQuality |
StateCount |
StateTimeTotal |
StateTimePercent |
|
SysPulse |
1 |
192 |
30 |
1800000 |
50 |
|
SysPulse |
0 |
192 |
30 |
1800000 |
50 |
The following query returns the minimum time in state, the minimum contained time in state, and value for the SysTimeSec system tag.
SELECT
TagName,
StartDateTime,
EndDateTime,
StateTimeMin as STM,
StateTimeMinContained as STMC,
Value
FROM StateSummaryHistory
WHERE TagName='SysTimeSec'
AND wwRetrievalMode='Cyclic'
AND wwResolution=5000
AND StartDateTime>='2009-10-21 17:40:00.123'
AND StartDateTime<='2009-10-21 17:40:05.000'
The results are:
|
TagName |
StartDateTime |
EndDateTime |
STM |
STMC |
Value |
|---|---|---|---|---|---|
|
SysTimeSec |
2009-10-21 17:40:00.123 |
2009-10-21 17:40:05.123 |
877 |
0 |
0 |
|
SysTimeSec |
2009-10-21 17:40:00.123 |
2009-10-21 17:40:05.123 |
1000 |
1000 |
1 |
|
SysTimeSec |
2009-10-21 17:40:00.123 |
2009-10-21 17:40:05.123 |
1000 |
1000 |
2 |
|
SysTimeSec |
2009-10-21 17:40:00.123 |
2009-10-21 17:40:05.123 |
1000 |
1000 |
3 |
|
SysTimeSec |
2009-10-21 17:40:00.123 |
2009-10-21 17:40:05.123 |
1000 |
1000 |
4 |
|
SysTimeSec |
2009-10-21 17:40:00.123 |
2009-10-21 17:40:05.123 |
123 |
0 |
5 |