SQL Query Engine Stored Procedures
This topic lists every stored procedure that the SQL Query Engine registers in SQL Server, with its parameters, its result set, and a working example. For query patterns that combine these procedures, see Querying Historical Data with the SQL Query Engine.
The stored procedures are registered in the master system database. In SQL Server Management Studio, you can find them in Object Explorer under System Databases > master > Programmability > Stored Procedures. All of them are prefixed with QE_.
Common Parameters
The procedures share a small set of parameters. You can pass parameters by name, as in the examples below, or by position in the order shown in each procedure's signature.
|
Parameter |
Type |
Description |
|---|---|---|
|
|
datetime2 |
Start of the time range to read. Timestamps are interpreted as UTC unless the SQL Query Engine is configured otherwise. |
|
|
datetime2 |
End of the time range to read. |
|
|
nvarchar |
Length of each interval that aggregated data is divided into. Pass either a time span in the form d.hh:mm:ss.fffffff (for example, 00:01:00 for one minute or 1.00:00:00 for one day) or a whole number of milliseconds (for example, 3600000 for one hour). |
|
|
nvarchar |
The Data Historian point to read, as returned in the PointName column of |
|
|
nvarchar |
(Optional) GENESIS Security user name. Defaults to |
|
|
nvarchar |
(Optional) Password of the GENESIS Security user. Defaults to |
Every procedure accepts @username and @password as its last two parameters. You can omit them when GENESIS Security is disabled, but they are required when it is enabled. For details and examples, see Using the SQL Query Engine with Security Enabled.
Status Columns
The procedures return a status code from Data Historian with every value. The raw-data procedures return it in the Quality column. The aggregate procedures return one status per aggregate: a numeric Status column and, where present, a Status_Str column holding the same status as text. A status code of 0 means Good, so filtering on Quality = 0 or MIN_Status = 0 keeps only the values that Data Historian reports as reliable. For the full set of codes and their meanings, see Data Historian Status Codes.
QE_GetAllPointNames
Returns a list of all Data Historian points and their metadata. Use this procedure to discover the point names to pass to the data query procedures.
Parameters
None, other than the optional @username and @password.
Output Columns
|
Column |
Type |
Description |
|---|---|---|
|
Path |
nvarchar |
Full path of the point in the Data Historian configuration, in the form |
|
DisplayName |
nvarchar |
Display name of the point. |
|
Description |
nvarchar |
Description of the point, if one is configured. |
|
PointName |
nvarchar |
The point name to pass as |
|
EngineeringUnits |
nvarchar |
Engineering units of the point value (for example, °C, bar, or rpm). |
|
RangeLow |
float |
The configured lower bound of the point's value range. |
|
RangeHigh |
float |
The configured upper bound of the point's value range. |
|
DataType |
int |
Numeric identifier of the point's data type. |
|
DataTypeName |
nvarchar |
Name of the point's data type (for example, Double, Int32, or Boolean). |
|
Timestamp |
datetime2 |
Timestamp of the record. |
Example—list every point:
Filtered Variants
Three variants return the same columns for a subset of points, selected by the Path column. Each takes one filter parameter followed by the optional @username and @password.
|
Procedure |
Parameter |
Returns |
|---|---|---|
|
|
|
Points whose path contains the specified text. |
|
|
|
Points whose path does not contain the specified text. |
|
|
|
Points whose path exactly matches the specified text. |
Example—list the points under the Signals folder:
QE_GetHistoryRawModified
Returns the raw samples that Data Historian logged for one or more points over a time range, one row per sample. This procedure returns the value as text. When you know the data type of the point, use one of the typed variants listed below, which return the value in the matching SQL Server type.
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
|
datetime2 |
Start of the time range. |
|
|
datetime2 |
End of the time range. |
|
|
nvarchar |
The point to read. To read several points in one call, pass their names separated by commas (for example, |
Output Columns
|
Column |
Type |
Description |
|---|---|---|
|
PointName |
nvarchar |
Name of the point the sample belongs to. |
|
Timestamp |
datetime2 |
Timestamp of the logged sample. |
|
Quality |
int |
Data Historian status code of the sample. 0 means Good. Learn More |
|
Value |
varies |
The logged value; |
Example—read the raw samples of one point over five minutes:
Typed Variants
The typed variants take the same parameters and return the same columns, with Value in the type shown.
|
Procedure |
Value Type |
|---|---|
|
|
bit |
|
|
tinyint |
|
|
smallint |
|
|
smallint |
|
|
int |
|
|
bigint |
|
|
int |
|
|
bigint |
|
|
decimal(20,0) |
|
|
real |
|
|
float |
|
|
datetime2 |
QE_GetHdaAnalog
Returns aggregated (processed) historical data for one numeric point. The procedure divides the time range into intervals of the length given by @resamplingInterval and returns one row per interval. Each row holds all of the aggregates listed in the table below at once; there is no parameter to select an aggregate. To work with a single aggregate, select its columns from the result set.
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
|
datetime2 |
Start of the time range. |
|
|
datetime2 |
End of the time range. |
|
|
nvarchar |
Length of each interval as a time span (00:01:00) or a number of milliseconds (60000). Learn more |
|
|
nvarchar |
The numeric point to read. |
Output Columns
The result set has a Timestamp column followed by a group of columns for each aggregate. Each group is named with the aggregate's prefix from the table below.
|
Column |
Type |
Description |
|---|---|---|
|
Timestamp |
datetime2 |
Start of the interval. |
|
|
float |
The aggregate value for the interval. |
|
|
int |
Data Historian status code of the aggregate value. 0 means Good. Learn More |
|
|
nvarchar |
The Status column value as text. |
|
|
datetime2 |
For |
Aggregates Returned
|
Column Prefix |
OPC HDA Aggregate |
Description |
|---|---|---|
|
|
MinimumActualTime |
Lowest value in the interval. |
|
|
MaximumActualTime |
Highest value in the interval. |
|
|
Average |
Arithmetic mean of the samples in the interval. |
|
|
TimeAverage |
Time-weighted average, which accounts for how long each value was held. More representative than |
|
|
Total |
Time-weighted total (integral) of the value over the interval. Useful for flow-rate or energy points. |
|
|
Interpolative |
Value interpolated at the start of the interval from the surrounding samples. |
|
|
End |
Last value in the interval. |
|
|
Delta |
Difference between the last and the first value in the interval. |
|
|
Range |
Difference between the highest and the lowest value in the interval. |
|
|
Sum |
Sum of the sample values in the interval. |
|
|
Count |
Number of samples in the interval. |
Example—read the aggregates of one point for a day, in one-hour intervals:
Example—keep only the hourly minimum, maximum, and average by loading the result into a table and selecting the columns you need:
QE_GetHdaAnalog5
Returns the same aggregates as QE_GetHdaAnalog for up to five numeric points in a single call, with one row per interval. Use it instead of calling QE_GetHdaAnalog five times when a report needs the same aggregates for several points over the same time range and interval.
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
|
datetime2 |
Start of the time range. |
|
|
datetime2 |
End of the time range. |
|
|
nvarchar |
Length of each interval as a time span or a number of milliseconds. |
|
|
nvarchar |
The five numeric points to read. All five are required. |
Output Columns
The result set has a Timestamp column followed by the aggregate columns for point 1, then point 2, and so on. The columns are named as for QE_GetHdaAnalog with the point's position appended: MIN_Value_1, MIN_Status_1, MIN_Timestamp_1, MAX_Value_1, and so on through COUNT_Status_5. The _Status_Str columns are not included.
Example—read the aggregates of five points in 20-second intervals:
QE_GetHdaBool
Returns aggregated historical data for one Boolean point, one row per interval. Use it to analyze state data such as equipment running status. Each row holds all of the aggregates listed below.
Parameters
The same as QE_GetHdaAnalog: @startTimestamp, @endTimestamp, @resamplingInterval, and @pointName, where the point is a Boolean point.
Output Columns
The result set has a Timestamp column (start of the interval) followed by <prefix>_Value, <prefix>_Status, and <prefix>_Status_Str columns for each aggregate, as for QE_GetHdaAnalog.
|
Column Prefix |
OPC HDA Aggregate |
Value Type |
Description |
|---|---|---|---|
|
|
DurationInStateZero |
float |
How long the point was false (0) during the interval. |
|
|
DurationInStateNonZero |
float |
How long the point was true (non-zero) during the interval. |
|
|
NumberOfTransitions |
int |
How many times the point changed state during the interval. |
|
|
Count |
int |
Number of samples in the interval. |
Example—read the hourly state summary of a running indicator:
QE_GetHdaBool5
Returns the same aggregates as QE_GetHdaBool for up to five Boolean points in a single call, with one row per interval.
Parameters
The same as QE_GetHdaAnalog5: @startTimestamp, @endTimestamp, @resamplingInterval, and @pointName1 to @pointName5, where the points are Boolean points. All five are required.
Output Columns
The result set has a Timestamp column followed by the aggregate columns for point 1, then point 2, and so on, named as for QE_GetHdaBool with the point's position appended: DURATION_IN_STATE_0_Value_1, DURATION_IN_STATE_0_Status_1, and so on through COUNT_Status_5. The _Status_Str columns are not included.