Delta retrieval - handling NULL values
- Last UpdatedFeb 28, 2025
- 2 minute read
The initial NULL value after a non-NULL is always returned. Multiple NULL values are suppressed. The first non-NULL after a NULL is always returned even if it is the same as the previous non-NULL value.
SELECT TagName, DateTime, Value, QualityDetail
FROM History
WHERE TagName = 'A001'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwRetrievalMode = 'Delta'
This query can be run against the following sample data:
|
Tagname |
DateTime |
Value |
QualityDetail |
|---|---|---|---|
|
A001 |
2009-09-12 00:17 |
0.8 |
192 |
|
A001 |
2009-09-12 00:24 |
0.0 |
249 |
|
A001 |
2009-09-12 00:27 |
0.0 |
249 |
|
A001 |
2009-09-12 00:28 |
0.5 |
192 |
|
A001 |
2009-09-12 00:31 |
0.0 |
249 |
|
A001 |
2009-09-12 00:33 |
0.0 |
24 |
|
A001 |
2009-09-12 00:35 |
0.0 |
24 |
|
A001 |
2009-09-12 00:36 |
0.5 |
192 |
The following is a graphical representation of the data:
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
|---|---|---|---|
|
A001 |
2009-09-12 00:20 |
0.8 |
192 |
|
A001 |
2009-09-12 00:24 |
NULL |
249 |
|
A001 |
2009-09-12 00:28 |
0.5 |
192 |
|
A001 |
2009-09-12 00:31 |
NULL |
249 |
|
A001 |
2009-09-12 00:36 |
0.5 |
192 |
The sample data points and the results are mapped on the following chart. Only the data falling between the time start and end marks at 00:20 and 00:40 (shown on the chart as dark vertical lines) are returned by the query.
Because there is no value that matches the start time, an initial value at 00:20 is returned in the results based on the value of the preceding data point at 00:16. Because there is no change in the value at 00:27 from the value at 00:24, the data point appears on the chart but does not appear in the results. Similarly, the two 0.0 values at 00:33 and 00:35 are also excluded from the results. However, the non-NULL value at 00:36 is returned, even though it is the same as the value at 00:28, because it represents a delta from the preceding (NULL) value at 00:35.