Trailing edge detection for discrete tags
- Last UpdatedFeb 06, 2025
- 2 minute read
If Trailing is specified as the parameter in the edge detection extension, the only rows in the result set are those that are the first to fail the criteria in the WHERE clause (returned false) after a row successfully met the WHERE clause criteria (returned true).
This example queries the History table. If the WHERE clause criteria specifies returning only discrete values equal to 1 (On), then applying a trailing edge detection is the same as reversing the WHERE clause (as if Value = 0 was applied).
SELECT DateTime, TagName, Value
FROM History
WHERE TagName IN ('SysPulse','MyPulse')
AND DateTime > '2001-12-08 00:59:00'
AND DateTime <= '2001-12-08 01:04:00'
AND Value = 1
AND wwEdgeDetection = 'Trailing'
The results are:
|
DateTime |
TagName |
Value |
|---|---|---|
|
2001-12-08 00:01:40.000 |
MyPulse |
1 |
|
2001-12-08 00:02:00.000 |
SysPulse |
1 |
|
2001-12-08 00:03:00.000 |
MyPulse |
1 |
|
2001-12-08 00:04:00.000 |
SysPulse |
1 |
This example queries the WideHistory table. It applies a trailing edge detection returns the boundaries where the condition ceases to be true (one of the values is equal to 0).
SELECT DateTime, SysPulse, MyPulse FROM OpenQuery(INSQL, 'SELECT DateTime, SysPulse, MyPulse
FROM WideHistory
WHERE DateTime > "2001-12-08 00:59:00"
AND DateTime <= "2001-12-08 01:04:00"
AND SysPulse = 1
AND MyPulse = 1
AND wwEdgeDetection = "Trailing"
')
The results are:
|
DateTime |
SysPulse |
MyPulse |
|---|---|---|
|
2001-12-08 00:01:40.000 |
1 |
1 |
|
2001-12-08 00:04:00.000 |
1 |
1 |
Compare these results with the same query using no edge detection, as shown in Edge detection for discrete tags. If you look at the diagram, you might think that a row could be returned at 00:03:00, but because both tags change at exactly this instant, their values are not returned. In a normal process, it is unlikely that two tags would change at exactly at the same instant.