Comparison Operators
The Historian OLE DB Provider supports the use of comparison symbols within SQL statements. The following table outlines the comparison operators supported.
Comparison Symbol | Meaning |
---|---|
< | Less Than |
> | Greater Than |
<= | Less Than or Equal |
>= | Greater Than or Equal |
= | Equal |
!= | Not Equal |
!> | Not Greater Than |
!< | Not Less Than |
BETWEEN x AND y | Between the values x and y inclusive, where x and y are numeric values |
The Historian OLE DB Provider does not support a literal on the left side of the comparison operator. For example, this statement would fail:
SELECT DISTINCT tagname FROM ihRawData WHERE 50>Value
But this statement succeeds, since the
Value
column is to the left of the >
operator:SELECT DISTINCT tagname FROM ihRawData WHERE Value>50
The following examples show other possible uses of these comparison symbols in SELECT statements.
Example 1: Retrieve Tags with a High EGU Greater Than 300
SELECT DISTINCT tagname, loengineeringunits, hiengineeringunits
FROM ihTags WHERE hiengineeringunits > 300
Example 2: Retrieve Tags with a Specific Description
SELECT tagname, description FROM ihTags WHERE description = "aa"
Example 3: Retrieve All Samples Where the Value Exceeds Query Supplied Values
SELECT timestamp, tagname, value FROM ihRawData WHERE samplingmode=rawbytime AND value>75
Example 4: Retrieve All Samples Where the Value is Between Query Supplied Values
SELECT timestamp, tagname, value FROM ihRawData WHERE samplingmode=lab AND value BETWEEN 25 AND 75
Example 5: Retrieve All Tag Names Starting with an A or B
SELECT * FROM ihtags WHERE tagname < 'C'