Quality rule - query examples
- Last UpdatedJul 18, 2024
- 5 minute read
To force a query to exclude points with doubtful OPC quality, specify the following in the query:
AND wwQualityRule = 'Good'
To force a query to use points with both good and doubtful OPC quality, specify the following in the query:
AND wwQualityRule = 'Extended'
If you include the wwQualityRule column in a SELECT statement, it will show which quality rule was used for the individual row, if applicable.
You can combine OPC qualities in a query. For example, if you combine a mixture of good OPC qualities (such as 192 to 219), a good OPC quality (192) will be returned as a combined result.
SELECT TagName, DateTime, Value, QualityDetail, OPCQuality, wwRetrievalMode
FROM History
WHERE TagName = 'I0R5'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'Avg'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
|---|---|---|---|
|
I0R5 |
2009-09-12 00:07 |
2 |
193 |
|
I0R5 |
2009-09-12 00:14 |
3 |
195 |
|
I0R5 |
2009-09-12 00:22 |
0 |
196 |
|
I0R5 |
2009-09-12 00:25 |
1 |
199 |
|
I0R5 |
2009-09-12 00:27 |
0 |
200 |
|
I0R5 |
2009-09-12 00:29 |
2 |
207 |
|
I0R5 |
2009-09-12 00:33 |
3 |
215 |
|
I0R5 |
2009-09-12 00:36 |
0 |
216 |
|
I0R5 |
2009-09-12 00:39 |
1 |
219 |
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
OPCQuality |
wwRetrievalMode |
|---|---|---|---|---|---|
|
I0R5 |
2009-09-12 00:20 |
2.6 |
192 |
192 |
AVERAGE |
|
I0R5 |
2009-09-12 00:30 |
1.0 |
192 |
192 |
AVERAGE |
|
I0R5 |
2009-09-12 00:40 |
1.6 |
192 |
192 |
AVERAGE |
Similarly, if you combine a mixture of doubtful OPC qualities, a doubtful OPC quality (64) will be returned as the combined OPC quality.
SELECT TagName, DateTime, Value, QualityDetail, OPCQuality, wwRetrievalMode
FROM History
WHERE TagName = 'I0R5'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'Integral'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
||
|---|---|---|---|---|---|
|
I0R5 |
2009-09-12 00:07 |
2 |
65 |
||
|
I0R5 |
2009-09-12 00:14 |
3 |
68 |
||
|
I0R5 |
2009-09-12 00:22 |
0 |
71 |
||
|
I0R5 |
2009-09-12 00:25 |
1 |
74 |
||
|
I0R5 |
2009-09-12 00:27 |
0 |
79 |
||
|
I0R5 |
2009-09-12 00:29 |
2 |
80 |
||
|
I0R5 |
2009-09-12 00:33 |
3 |
88 |
||
|
I0R5 |
2009-09-12 00:36 |
0 |
92 |
||
|
I0R5 |
2009-09-12 00:39 |
1 |
64 |
||
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
OPCQuality |
wwRetrievalMode |
|---|---|---|---|---|---|
|
I0R5 |
00:20 |
26.0 |
64 |
64 |
INTEGRAL |
|
I0R5 |
00:30 |
10.0 |
64 |
64 |
INTEGRAL |
|
I0R5 |
00:40 |
16.0 |
64 |
64 |
INTEGRAL |
When you combine the same OPC quality then that OPC quality will be returned. However, when there is no good point in a cycle for cyclic modes such as Integral, Average, Counter, or AnalogSummary, the returned NULL value will have an OPC quality of 0 and a Quality Detail of 65536, regardless of combined qualities.
SELECT TagName, StartDateTime, EndDateTime, OPCQuality, PercentGood, wwRetrievalMode, first
FROM AnalogSummaryHistory
WHERE TagName = 'F0R5'
AND StartDateTime >= '2009-09-12 00:20'
AND EndDateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'Cyclic'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
|---|---|---|---|
|
F0R5 |
2009-09-12 00:07 |
1.6 |
78 |
|
F0R5 |
2009-09-12 00:14 |
3.1 |
78 |
|
F0R5 |
2009-09-12 00:22 |
0.2 |
78 |
|
F0R5 |
2009-09-12 00:25 |
0.8 |
78 |
|
F0R5 |
2009-09-12 00:27 |
0.4 |
78 |
|
F0R5 |
2009-09-12 00:29 |
2.2 |
78 |
|
F0R5 |
2009-09-12 00:33 |
3.3 |
78 |
|
F0R5 |
2009-09-12 00:36 |
0.3 |
78 |
|
F0R5 |
2009-09-12 00:39 |
1.2 |
78 |
The results are:
|
Tagname |
StartDate Time |
EndDate Time |
OPCQuality |
PercentGood |
wwRetrievalMode |
first |
|---|---|---|---|---|---|---|
|
F0R5 |
2009-09-12 00:20 |
2009-09-12 00:30 |
78 |
100 |
CYCLIC |
0.200 |
|
F0R5 |
2009-09-12 00:30 |
2009-09-12 00:40 |
78 |
100 |
CYCLIC |
3.300 |
SELECT TagName, DateTime, Value, QualityDetail, OPCQuality, wwRetrievalMode
FROM History
WHERE TagName = 'F0R5'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'Avg'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
|---|---|---|---|
|
F0R5 |
2009-09-12 00:07 |
1.6 |
15 |
|
F0R5 |
2009-09-12 00:14 |
3.1 |
15 |
|
F0R5 |
2009-09-12 00:22 |
0.2 |
15 |
|
F0R5 |
2009-09-12 00:25 |
0.8 |
15 |
|
F0R5 |
2009-09-12 00:27 |
0.4 |
15 |
|
F0R5 |
2009-09-12 00:29 |
2.2 |
15 |
|
F0R5 |
2009-09-12 00:33 |
3.3 |
15 |
|
F0R5 |
2009-09-12 00:36 |
0.3 |
15 |
|
F0R5 |
2009-09-12 00:39 |
1.2 |
15 |
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
OPCQuality |
wwRetrievalMode |
|---|---|---|---|---|---|
|
F0R5 |
2009-09-12 00:20 |
NULL |
65536 |
0 |
AVERAGE |
|
F0R5 |
2009-09-12 00:30 |
NULL |
65536 |
0 |
AVERAGE |
|
F0R5 |
2009-09-12 00:40 |
NULL |
65536 |
0 |
AVERAGE |
When you combine a mixture of good, bad, and uncertain OPC qualities, a doubtful OPC quality (64) will be returned as a combined result.
SELECT TagName, DateTime, Value, QualityDetail, OPCQuality, wwRetrievalMode
FROM History
WHERE TagName = 'F0R5'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'Avg'
AND wwQualityRule = 'Optimistic'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
|---|---|---|---|
|
F0R5 |
2009-09-12 00:07 |
1.6 |
15 |
|
F0R5 |
2009-09-12 00:14 |
3.1 |
69 |
|
F0R5 |
2009-09-12 00:22 |
0.2 |
78 |
|
F0R5 |
2009-09-12 00:25 |
0.8 |
200 |
|
F0R5 |
2009-09-12 00:27 |
0.4 |
15 |
|
F0R5 |
2009-09-12 00:29 |
2.2 |
92 |
|
F0R5 |
2009-09-12 00:33 |
3.3 |
88 |
|
F0R5 |
2009-09-12 00:36 |
0.3 |
199 |
|
F0R5 |
2009-09-12 00:39 |
1.2 |
196 |
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
OPCQuality |
wwRetrievalMode |
|---|---|---|---|---|---|
|
F0R5 |
2009-09-12 00:20 |
2.012 |
64 |
64 |
AVERAGE |
|
F0R5 |
2009-09-12 00:30 |
0.820 |
64 |
64 |
AVERAGE |
|
F0R5 |
2009-09-12 00:40 |
1.751 |
64 |
64 |
AVERAGE |
For RoundTrip, StateSummary, and ValueState modes, the OPC qualities are only combined with the same state in a cycle. If the state only occurs once in a cycle, then the qualities of that state will be returned. The returned NULL state will always have an OPC quality of 0 and Quality Detail of 65536. The same qualities are returned for a state that has no roundtrip in RoundTrip mode.
SELECT TagName, DateTime, Value, QualityDetail, OPCQuality, StateTime
FROM History
WHERE TagName = 'I001'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'RoundTrip'
AND wwStateCalc = 'MaxContained'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
|---|---|---|---|
|
I001 |
2009-09-12 00:12 |
1 |
90 |
|
I001 |
2009-09-12 00:15 |
2 |
65 |
|
I001 |
2009-09-12 00:22 |
1 |
85 |
|
I001 |
2009-09-12 00:23 |
2 |
75 |
|
I001 |
2009-09-12 00:26 |
1 |
75 |
|
I001 |
2009-09-12 00:29 |
2 |
70 |
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
OPC-Quality |
StateTime |
|---|---|---|---|---|---|
|
I001 |
2009-09-12 00:20 |
NULL |
65536 |
0 |
NULL |
|
I001 |
2009-09-12 00:20 |
1.0 |
90 |
90 |
NULL |
|
I001 |
2009-09-12 00:20 |
2.0 |
65 |
65 |
NULL |
|
I001 |
2009-09-12 00:20 |
1.0 |
64 |
64 |
4000 |
|
I001 |
2009-09-12 00:20 |
2.0 |
64 |
64 |
6000 |
The returned Quality Detail is the same as OPC quality unless there is special flag for certain indication for example when there is indication for role over in counter mode.
SELECT TagName, DateTime, Value, QualityDetail, OPCQuality
FROM History
WHERE TagName = 'I0R5'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'Avg'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
|---|---|---|---|
|
I0R5 |
2009-09-12 00:07 |
2 |
218 |
|
I0R5 |
2009-09-12 00:14 |
3 |
218 |
|
I0R5 |
2009-09-12 00:22 |
0 |
218 |
|
I0R5 |
2009-09-12 00:25 |
1 |
218 |
|
I0R5 |
2009-09-12 00:27 |
0 |
218 |
|
I0R5 |
2009-09-12 00:29 |
2 |
218 |
|
I0R5 |
2009-09-12 00:33 |
3 |
218 |
|
I0R5 |
2009-09-12 00:36 |
0 |
218 |
|
I0R5 |
2009-09-12 00:39 |
1 |
218 |
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
OPCQuality |
|---|---|---|---|---|
|
I0R5 |
2009-09-12 00:20 |
2.6 |
218 |
218 |
|
I0R5 |
2009-09-12 00:30 |
1.0 |
218 |
218 |
|
I0R5 |
2009-09-12 00:40 |
1.6 |
218 |
218 |
For Interpolated mode only the returned row with Linear wwInterpolationType will have combined qualities.
SELECT TagName, DateTime, Value, QualityDetail, OPCQuality, wwRetrievalMode, wwInterpolationType
FROM History
WHERE TagName = 'I0R5'
AND DateTime >= '2009-09-12 00:20'
AND DateTime <= '2009-09-12 00:40'
AND wwResolution = 10000
AND wwRetrievalMode = 'Interpolated'
AND wwInterpolationType = 'Linear'
If you run this query against the following sample data:
|
Tagname |
DateTime |
Resolution |
QualityDetail |
|---|---|---|---|
|
I0R5 |
2009-09-12 00:07 |
2 |
193 |
|
I0R5 |
2009-09-12 00:14 |
3 |
195 |
|
I0R5 |
2009-09-12 00:22 |
0 |
196 |
|
I0R5 |
2009-09-12 00:25 |
1 |
199 |
|
I0R5 |
2009-09-12 00:27 |
0 |
200 |
|
I0R5 |
2009-09-12 00:29 |
2 |
207 |
|
I0R5 |
2009-09-12 00:33 |
3 |
215 |
|
I0R5 |
2009-09-12 00:36 |
0 |
216 |
|
I0R5 |
2009-09-12 00:39 |
1 |
219 |
The results are:
|
Tagname |
DateTime |
Value |
QualityDetail |
OPCQuality |
|---|---|---|---|---|
|
I0R5 |
2009-09-12 00:20 |
0.8 |
192 |
192 |
|
I0R5 |
2009-09-12 00:30 |
2.3 |
192 |
192 |
|
I0R5 |
2009-09-12 00:40 |
1.0 |
192 |
219 |
Note: Cyclic, Full, Delta, Maximum, Minimum, and BestFit do not have combined qualities; therefore, the rules are not applied to these modes.