Professional Documents
Culture Documents
Historian
Retrieval Guide
Version 2020
January 2020
© 2020 AVEVA Group plc and its subsidiaries. All rights reserved.
No part of this documentation shall be reproduced, stored in a ret rieval system, or transmitted by any
means, electronic, mechanical, photocopying, rec ording, or otherwise, without the prior written
permission of AVEVA. No liability is assumed with respect to the use of the information contained herein.
Although precaution has been taken in the preparation of this documentation, AVEVA assumes no
responsibility for errors or omissions. The information in this documentation is subject to change without
notice and does not represent a commitment on the part of AVEVA. The soft ware described in this
documentation is furnished under a license agreement. This soft ware may be used or copied only in
accordance with the terms of such license agreement.
ArchestrA, Aquis, Avantis, Citect, DYNSIM, eDNA, EYESIM, InBatch, InduSoft, InStep, Int elaTrac,
InTouch, OASyS, PIPEPHASE, PRiSM, PRO/II, PROV ISION, ROMeo, SIM4ME, SimCentral, SimSci,
Skelta, SmartGlance, Spiral Software, Termis, WindowMaker, WindowViewer, and Wonderware are
trademarks of AVEVA and/or its subsidiaries. An extensive listing of AVEVA trademarks can be found at:
https://sw.aveva.com/legal. All other brands may be trademarks of their respective owners.
Publication date: Friday, February 7, 2020
Contact Information
AVEVA Group plc
High Cross
Madingley Road
Cambridge
CB3 0HB. UK
https://sw.aveva.com/
For information on how to cont act sales, customer training, and technical support, see
https://sw.aveva.com/contact.
AVEVA™ Historian Retrieval Guide
Contents
Welcome .................................................................................................................................... 9
AVEVA Historian Documentation Set ......................................................................................... 9
Version 2020 3
AVEVA™ Historian Retrieval Guide Contents
4 Version 2020
Contents AVEVA™ Historian Retrieval Guide
Version 2020 5
AVEVA™ Historian Retrieval Guide Contents
6 Version 2020
Contents AVEVA™ Historian Retrieval Guide
Version 2020 7
AVEVA™ Historian Retrieval Guide
Welcome
This guide describes how to retrieve data that is stored by an AVEVA Historian server.
You can retrieve data by using:
Trans act-SQL queries.
Historian Client tools for query construction, queries within Excel workbooks, and trend mapping.
Historian Insight, a web-based tool for tag-based searches and charting. With Insight, you can save
and reuse content (sets of tags and defined timeframes), and can share, embed, and download the
results. Historian Insight is installed as a part of AVEVA Historian.
Historian SDK.
Tools that use the RES T ODat a interface.
Version 2020 9
AVEVA™ Historian Retrieval Guide
C HAPTER 1
About Data Retrieval
Through the Data Retrieval subsystem, AVEVA Historian receives SQL queries from clients, locates the
requested data, performs necessary processing, and then returns the results.
For configuration and event data, retrieval is made possible by normal SQL queries, because these
types of data are stored in SQL Server database tables. Historical data, however, must be retrieved from
history blocks and then sent to clients as if it is stored in SQL Server tables.
To accomplish retrieval from both data repositories, the Data Retrieval subsystem includes:
An implementation of a SQL Server data provider.
This determines whether the requested data is saved in SQL Server tables or in history blocks.
Retrieval subsystem.
This subsystem is responsible for extracting the requested data from the history blocks and
presenting to the AVEVA Historian OLE DB provider as "virtual" history tables.
A set of SQL Server extensions.
These are implemented as columns in the history tables. You can us e these extensions to specify
the nature of the rowset that is returned, such as the number of rows returned, the resolution of the
data, or the retrieval mode.
For more information on data storage, see Managing Data Storage.
Note: If you have an application that uses the older SQL Server dat etime format, be aware that some
rounding can occur as compared to the newer datetime2 format (for example, 3.3ms vs. 100ns).
Version 2020 11
AVEVA™ Historian Retrieval Guide About Data Retrieval
All tag data is stored in history blocks. For more information on history blocks, see Managing Partitions
and History Blocks in the AVEVA Historian Administration Guide.
OLE DB technology can be used to access data in any remote data store. This access is accomplished
though a soft ware component called an OLE DB provider.
Retrieval subsystem
The Retrieval subsystem does the following:
Fetches history data from history blocks on disk.
Formats data so that it can be passed up through the system to the AVEVA Historian OLE DB
provider or other HCAL-enabled client applications.
Returns information regarding the history blocks, such as the start and end dates and the location.
To access AVEVA Historian historical data using OLE DB, any COM -based client application must
connect directly to the SQL Server and then specify to use the AVEVA Historian OLE DB provider in the
syntax of the query.
When you execute a query and specify the AVEVA Historian OLE DB provider in the syntax, the
Microsoft SQL Server pars er will pass the appropriat e parts of the data request to the AVEVA Historian
OLE DB provider. The AVEVA Historian OLE DB provider will then interface with the retrieval service to
locate the data store, extract the requested information, and return the data to the Microsoft SQL Server
as a rowset. Microsoft SQL Server will perform any other processing required on the data and ret urn the
data to the client application as a result set and a set of output parameters, if applicable.
The AVEVA Historian OLE DB provider must be present on the server running Microsoft SQL Server.
The set of Trans act-SQL operations that can be used to retrieve data in the history blocks depends on
the capabilities of the AVEVA Historian OLE DB provider.
For more information on OLE DB, see your Microsoft documentation.
12 Version 2020
About Data Retrieval AVEVA™ Historian Retrieval Guide
Data access from the history blocks is made possible by SQL Server's OLE DB provider technology.
Client applications must connect directly to the Mic rosoft SQL S erver and t hen specify to use the AVEVA
Historian OLE DB provider in the syntax of the query.
The extension tables are:
History [INSQL].Runtime.dbo.History
Live [INSQL].Runtime.dbo.Live
AnalogSummaryHistory [INSQL].Runtime.dbo.AnalogSummary History
StateSummaryHistory [INSQL].Runtime.dbo.StateSummaryHistory
HistoryBlock [INSQL].Runtime.dbo.HistoryBlock
E vents [INSQL].Runtime.dbo.E vents
For more information on the history extension tables, see History Tables and Views in the Historian
Database Reference.
Legacy Process Data Extension Tables
These are legacy (backward compatible) extension tables for process data:
AnalogHistory [INSQL].Runtime.dbo.AnalogHistory
DiscreteHistory [INSQL].Runtime.dbo.DiscreteHistory
StringHistory [INSQL].Runtime.dbo.StringHistory
AnalogLive [INSQL].Runtime.dbo.AnalogLive
DiscreteLive [INSQL].Runtime.dbo.DiscreteLive
StringLive [INSQL].Runtime.dbo.StringLive
The AnalogHistory, DiscreteHistory, StringHistory, and History tables are the only tables which are
updateable. The remaining tables are read -only.
For more information about these tables, see Backward Compatibility Entities in the Historian Dat abase
Referenc e.
Legacy Event Data Extension Tables
These are legacy (backward compatible) extension tables for events:
Version 2020 13
AVEVA™ Historian Retrieval Guide About Data Retrieval
sp_addlinkedserver
@server = 'INSQL',
@srvproduct = '',
@provider = 'INSQL'
go
sp_serveroption 'INSQL','collation compatible',true
go
sp_addlinkedsrvlogin 'INSQL','TRUE',NULL,NULL,NULL
go
"INSQL" is the name of the AVEVA Historian OLE DB provider as the link ed server. Use this name to
specify the AVEVA Historian OLE DB provider in a query.
To perform joins between the legacy analog history tables and discrete history tables, the installatio n
program also creates an alias for the same AVEVA Historian OLE DB provider:
sp_addlinkedserver
@server = 'INSQLD',
@srvproduct = '',
@provider = 'INSQL'
go
sp_serveroption 'INSQLD','collation compatible',true
go
sp_addlinkedsrvlogin 'INSQLD','TRUE',NULL,NULL,NULL
go
For example, if you want to execute a query that performs this type of join, use the normal alias in
specifying the first table (the analog history table), and use the second alias in specifying the second
table (the discrete history table, hence the "D" added to the alias name).
14 Version 2020
About Data Retrieval AVEVA™ Historian Retrieval Guide
For example, the AVEVA Historian I/O Server could be used by InTouch WindowViewer to access
system tag values provided by the AVEVA Historian to monitor system health. You could configure
WindowViewer to generate an alarm when abnormal behavior is detected within the AVEVA Historian.
By default, the AVEVA Historian I/O Server runs as a Windows service and can be started and stopped
using the System Management Console. You can also monitor the AVEVA Historian I/ O Server from
within the System Management Console. For more information on the System Management Console,
see About Administrative Tools in the AVEVA Historian Administration Guide.
The AVEVA Historian I/O Server is a read-only server; clients cannot update data.
The AVEVA Historian I/O Server sends the original OPC quality as it was stored in the AVEVA Historian.
The OP C quality remains the same throughout the system, including storage, retrieval, and the AVEVA
Historian I/O Server.
SELECT select_list
FROM table_source
WHERE search_condition
[ GROUP BY group_by_expression ]
[ HAVING search_condition ]
[ ORDER BY order_expression [ ASC | DESC ] ]
A WHERE clause is mandatory when issuing a SELECT query against any extension table except
HistoryBlock.
There are four variations for issuing a SELECT statement to the AVEVA Historian OLE DB provider to
retrieve history data:
Using the Four-Part Naming Convention on page 15
Using an AVEVA Historian OLE DB Provider View on page 16
Using the OPE NQUERY Function on page 17
Using the OPE NROWSET Function on page 17
You should use the four-part name or a provider view to specify the extension table, whenever possible.
However, there are instances when the OPE NQUERY or OPENROWSE T function must be used, such
as for queries on wide tables.
For general information on creating SQL queries, see your Microsoft SQL Server documentation.
Version 2020 15
AVEVA™ Historian Retrieval Guide About Data Retrieval
catalog Catalog in the OLE DB dat a source that contains the object from which you want to
retrieve data. For Microsoft SQL Server type databases, this is the name of the
database. To use the AVEVA Historian OLE DB provider, the catalog name will
always be "Runtime."
schema Schema in the catalog that contains the object. For Microsoft SQL Server type
databases, this is the name of the login ID for accessing the data. To use the AVEVA
Historian OLE DB provider, the catalog name will always be "dbo."
object_name Data object that the OLE DB provider can expose as a rowset. For the AVEVA
Historian OLE DB provider, the object name is the name of the remote table that
contains the dat a you want to retrieve. For example, the History table.
In the case of four-part queries, SQL Server produces the statement that is sent to the AVEVA Historian
OLE DB provider from the statement that the user executes. Sometimes this produced statement is
incorrect, too complex, or lacks portions of the W HERE clause required for the A VEVA Historian OLE DB
provider to return data.
A typical error message when executing unsupported syntax is:
For four-part queries against non-English SQL Servers running on non -English operating systems, the
default date format might differ from the English versions. For example, for a French or German SQL
Server running on the corresponding operating system, the date/time in a four -part query must be:
yyyy-dd-mm hh:mm:ss.fff
For example:
2003-28-09 09:00:00.000
The default SQL date format is dependent on SQL Server and not on the operating system used.
However, you can modify the format using the SQL Server Convert() method. The output of this method
can be determined by the regional settings configured for the operating system.
Note: Backward compatibility views are named according to the v_P roviderTableName convention.
16 Version 2020
About Data Retrieval AVEVA™ Historian Retrieval Guide
For example:
Version 2020 17
AVEVA™ Historian Retrieval Guide About Data Retrieval
Note: If the OpenRowS et/OpenDatasource component is turned off as part of the security configuration
for the server, you will receive an error when you try to run this query. If necessary, a system
administrator can reset SQL Server settings to enable us e of ad hoc queries by executing the
sp_configure command.
GROUP BY Yes No
18 Version 2020
About Data Retrieval AVEVA™ Historian Retrieval Guide
The LIKE clause is only supported for the TagName and Value columns. The syntax " ... Value LIKE
'a string' ... " is only supported for a string table. For example:
IN Clause Limitations
If you are querying analog, discrete, or string tags from the AnalogTag, DiscreteTag, or StringTag tables
(respectively), you cannot use the LIKE clause within an IN clause to condition the tagname unless you
are ret urning the vValue column. This restriction applies if you are using the four-part naming convention
or an extension table view.
For example:
OR Clause Limitations
You cannot use the OR clause to specify more than one condition for a time domain extension. For more
information, see AVEVA Historian Time Domain E xtensions on page 24.
Joins are not supported within a single OPENQUE RY statement. For example, the following query
contains an implicit join between the Tag and Live tables, and will fail:
Version 2020 19
AVEVA™ Historian Retrieval Guide About Data Retrieval
Using a sub-SELE CT with a query on a normal SQL Server table and an extension table shoul d be
avoided; it is very inefficient due to the way SQL Server executes the query. For example:
20 Version 2020
About Data Retrieval AVEVA™ Historian Retrieval Guide
In general, use the following pattern for INNE R REMOTE JOIN queries against the historian is:
<SQLServerTable> INNER REMOTE JOIN <HistorianExtensionTable>
For more information on INNE R REMOTE JOIN, see your Microsoft SQL Server documentation.
In some rare cases, the SQL Server query processor truncates the WHERE clause in an attempt to
optimize the query. If you execute a query with a WHE RE clause, but an error message is returned
stating that no WHERE clause was received by the SQL Server, simply add another condition clause to
the query.
For example, in the following query, the SQL Server query processor optimizes out the WHE RE clause,
because it is superfluous.
The CONVERT function is not supported on the vV alue column in an OPE NQUERY statement. If you are
using OPENQUE RY on the History table, you must filter on the vValue column outside of the query.
In the following example, the value of the vValue column is converted to a float. Note that no string tags
are included in the query.
Version 2020 21
AVEVA™ Historian Retrieval Guide About Data Retrieval
The SQL Server query optimizer may incorrectly parse a complex query and not send cert ain query
criteria to the Historian OLE DB provider for handling. This can caus e unexpected results for the data.
If you suspect that this is happening, use SQL Server Management Studio tools to examine the query
plan that the optimizer is using and then modify your query so that the needed criteria gets directed to the
Historian OLE DB provider.
For example, the following query will be incorrectly parsed:
SELECT GETDATE()
DECLARE @TagList TABLE (TagName nvarchar(256))
INSERT @TagList
SELECT 'SysTimeSec' UNION
SELECT 'SysPerfCPUTotal'
-- Prevent the TagName criteria from being sent to the Historian OLE DB provider
(incorrect)
SELECT DateTime, h.vValue, h.TagName
FROM History h
INNER REMOTE JOIN @TagList l
ON h.TagName = l.TagName
WHERE DateTime >= DATEADD(hour,-1,GETDATE())
AND DateTime < GETDATE()
AND wwRetrievalMode = 'AVG'
AND wwCycleCount=1
22 Version 2020
About Data Retrieval AVEVA™ Historian Retrieval Guide
GO
To correct this issue, rewrite the query so that the tagname criteria is passed to the Historian OLE DB
provider correctly.
SELECT GETDATE()
DECLARE @TagList TABLE (TagName nvarchar(256))
INSERT @TagList
SELECT 'SysTimeSec' UNION
SELECT 'SysPerfCPUTotal'
-- Force the TagName criteria to be sent to the InSQL OLE DB Provider (correct)
SELECT DateTime, h.vValue, h.TagName
FROM @TagList l
INNER REMOTE JOIN History h
ON h.TagName = l.TagName
WHERE DateTime >= DATEADD(hour,-1,GETDATE())
AND DateTime < GETDATE()
AND wwRetrievalMode = 'AVG'
AND wwCycleCount=1
GO
If you use a column of a variant type as the parameter for some functions, SQL Server returns a syntax
error. However, the error is not passed to the Historian OLE DB provider to return to clients.
For example, in the following query, the rounding is specified for the vValue column, which is of type
variant. The query does not work, but no error is returned by the Historian OLE DB provider.
You cannot use StartDateTime in the query criteria instead of DateTime. For example, the following
query works, except that it does not apply the StartDateTime >= @Start Date claus e.
SET NOCOUNT ON
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
SET @StartDate = DateAdd(mi,-30,GetDate())
SET @EndDate = GetDate()
SET NOCOUNT OFF
SELECT History.TagName, DateTime = convert(nvarchar, DateTime, 21), Value,
vValue, StateTime, StartDateTime
FROM History
WHERE History.TagName IN ('Reactor1Level')
AND wwRetrievalMode = 'RoundTrip'
AND wwStateCalc = 'AvgContained'
AND vValue = convert(SQL_VARIANT, '1')
AND wwCycleCount = 1
AND wwTimeStampRule = 'Start'
AND wwQualityRule = 'Good'
Version 2020 23
AVEVA™ Historian Retrieval Guide About Data Retrieval
SQL Server returns an error for a query that contains a comparison statement like 'Value > 0' whenever
a NULL is returned. Be sure that you always include 'AND Value IS NOT NULL', so that the NULL values
are filtered out.
Note: The wwP arameters and wwMaxStates parameters are reserved for future use. The
wwRowCount paramet er is still supported, but is deprecated in favor of wwCycleCount.
The extensions are implemented as "virtual" columns in the extension tables. When you query an
extension table, you can specify values for these column parameters to manipulate the dat a that will be
returned. You will need to specify any real-time extension parameters each time that you execute the
query.
For example, you could specify a value for the wwResolution column in the query so that a resolution is
applied to the returned data set:
24 Version 2020
About Data Retrieval AVEVA™ Historian Retrieval Guide
Note: You cannot use the IN clause or OR clause to specify more than one condition for a time domain
extension. For example, "wwVersion IN ('original', 'latest')" and "wwRetrievalMode =
'Delta' OR wwVersion = 'latest'" are not supported.
For general information on creating SQL queries, see your Microsoft SQL Server documentation.
Version 2020 25
AVEVA™ Historian Retrieval Guide
C HAPTER 2
Data Retrieval Options
You can use a variety of retrieval modes and options to suit different reporting needs and applications.
Cyclic Retrieval
Cyclic retrieval is the retrieval of stored dat a for t he given time period based on a specified cyclic retrieval
resolution, regardless of whether or not the value of the tag(s) has changed. It works with all types of
tags. Cyclic retrieval produces a virtual rowset, which may or may not correspond to the actual data rows
stored on the AVEVA Historian.
Version 2020 27
AVEVA™ Historian Retrieval Guide Data Retrieval Options
In cyclic retrieval, one row is returned for each "cycle boundary." You specify the number of cycles either
directly or by means of a time resolution, that is, the spacing of cycle boundaries in time. If you specify a
number of cycles, the AVEVA Historian returns that number of rows, evenly spaced in time over the
requested period. The cyclic resolution is calculated by dividing the requested time period by the number
of cycle boundaries. If you specify a resolution, the number of cycles is calculated by dividing the time
period by the resolution.
If no data value is actually stored at a cycle boundary, the last value before the boundary is returned.
Beginning with AVEVA System Platform 2014 R2 SP1, Historian cyclic storage rules improve the
handling of "slow rate change" data tags. Instead of delaying posts to the databas e if tag values do not
arrive in a timely manner, new rules define a cyclic timeout when the database will be updated anyway.
That timeout is typically one-half the period for the tag’s cycle storage rate or the database server’s
maximum cyclic storage timeout, whichever is shorter. The time out is controlled by a the system
parameter MaxCyclicStorageTimeout. For more information, see System Parameters in the AVEVA
Historian Administration Guide.
The default retrieval mode is cyclic for retrieval from analog tables, including analog and state summary
tables.
Cyclic retrieval is fast and therefore consumes little server resources. However, it may not correctly
reflect the stored data because important proc ess values (gaps, spikes, etc.) might fall bet ween cycle
boundaries. For an alternative, see Best Fit Retrieval (see "Best Fit Retrieval" on page 41).
The following illustration shows how values are returned for cyclic retrieval:
Data is retrieved in cyclic mode with a start time of TC0 and an end time of TC2. The resolution has been
set in such a way that the historian returns data for three cycle boundaries at TC0, TC1, and TC2. Each dot
in the graphic represents an actual data point stored on the historian. From thes e points, the following
are returned:
At TC0: P2, because it falls right on the cycle boundary
At TC1: P7, because it is the last point before the cycle boundary
At TC2: P11, for the same reason
28 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
wwRetrievalMode = 'Cyclic'
For example, the following query returns data values for the analog tag 'ReactLevel'. If you do not specify
a wwCycleCount or wwResolution, the query will return 100 rows (the default).
Version 2020 29
AVEVA™ Historian Retrieval Guide Data Retrieval Options
No special handling is done for initial values. The initial value will behave like a normal cycle boundary at
the start time. For information on initial values, see Delta Retrieval - Initial Values on page 34.
No special handling is done for NULL values. They are returned just like any other value.
Delta Retrieval
Delta retrieval, or retrieval based on exception, is the ret rieval of only the changed values for a tag (s) for
the given time interval. That is, duplicate values are not returned. It works with all types of tags.
Delta retrieval always produces a rowset comprised of only rows that are actually stored on the historian;
that is, a delta query returns all of the physical rows in history for the specified tags, over the specified
period, minus any duplicate values. If there is no actual data point at the start time, the last data point
before the start time is returned.
Delta retrieval is the default mode for discrete and string tables and from the History table.
The following illustration shows how values are returned for delta retrieval:
Data is retrieved in delta mode with a start time of T1 and an end time of T2. Each dot in the graphic
represents an actual dat a point stored on the historian. From these points, the following are returned:
P2, because there is no actual dat a point at T1
P5, P8, P9, P10, and P11, because they repres ent changed values during the time period
For delta retrieval for replicated summary tags on a tier-2 historian, if a point with doubtful quality is
returned as the result of a value selection from an input summary point with a cont ained gap, the same
point can be returned again with good quality if the same value is selected again from the next input
summary point that has good quality.
You can use various parameters to adjust which values are returned in delta retrieval mode. For more
information, see the following sections:
Time Deadband (wwTimeDeadband) on page 95
30 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
To use the delta retrieval mode, set the following parameter in your query.
wwRetrievalMode = 'Delta'
Version 2020 31
AVEVA™ Historian Retrieval Guide Data Retrieval Options
The sample data points and the res ults are mapped on the following chart. Only the data falling between
the time start and end marks at 2009 -09-12 00:20 and 2009-09-12 00:40 (shown on the chart as dark
vertical lines) are ret urned by the query.
Because there is no value that matches the start time, an initial value at 2009-09-12 00: 20 is returned in
the results based on the value of the preceding data point at 2009-09-12 00:16. Because there is no
change in the value at 2009-09-12 00:27 from the value at 2009-09-12 00:24, the data point appears on
the chart but does not appear in the results. Similarly, the second 0.0 value at 2009 -09-12 00:29 is also
excluded from the results.
You can further cont rol the number of rows ret urned by using the wwTimeDeadband,
wwV alueDeadband, and wwCycleCount extensions. The use of a cycle count returns the first number of
rows within the time range of the query. For more information, see -old-Using wwResolution,
wwCycleCount, and wwRetrievalMode in the Same Query .
Also, the use of a time deadband and/or value deadband with delta retrieval produces differing results.
For more information, see Time Deadband (wwTimeDeadband) on page 95 and Value Deadband
(wwValueDeadband) on page 99.
32 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Version 2020 33
AVEVA™ Historian Retrieval Guide Data Retrieval Options
34 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
The sample data points and the res ults 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 prec eding data point at 00:16. Because there is no c hange 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.
Full Retrieval
In full retrieval mode, all stored data points are returned, regardless of whether a value or quality has
changed since the last value. This mode allows the same value and quality pair (or NULL value) to be
returned consecutively with their actual timestamps. It works with all types of tags.
By using full retrieval in conjunction with storage wit hout filtering (that is, no delta or cyclic storage mode
is applied at the historian), you can retrieve all values that originated from the plant floor dat a source or
from another application.
Version 2020 35
AVEVA™ Historian Retrieval Guide Data Retrieval Options
Full retrieval best repres ents the process measurements recorded by the AVEVA Historian. However, it
creates a higher load for the server, the net work and the client system because a very large number of
records may be returned for longer time periods.
For full retrieval for replicated summary tags on a tier -2 historian, if a point with doubtful quality is
returned as the result of a value selection from an input summary point with a cont ained gap, the same
point can be returned again with good quality if the same value is selected again from the next input
summary point that has good quality.
The following illustration shows how values are returned for full retrieval:
Data is retrieved in full mode with a start time of T1 and an end time of T2. Each dot in the graphic
represents an actual dat a point stored on the historian. From these points, the following are returned:
P2, because there is no actual dat a point at T1
P3 through P 12, because they represent stored data points during the time period
You can use various parameters to adjust which values are returned in full retrieval mode. For more
information, see the following sections:
History Version (wwVersion) on page 102
Qualit y Rule (wwQualit yRule) on page 109
36 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Full retrieval mode handles initial values the same way as delt a mode. For more information on initial
values, see Delta Retrieval - Initial Values on page 34.
Interpolated Retrieval
Interpolated retrieval works like cyclic retrieval, except that interpolated values are returned if there is no
actual data point stored at the cycle boundary.
This retrieval mode is useful if you want to retrieve cyclic data for slow -changing tags. For a trend,
interpolated retrieval res ults in a smoother curve instead of a "s tair-stepped" curve. This mode is also
useful if you have a slow-changing tag and a fast-changing tag and want to retrieve data for both. Finally,
some advanced applications require more evenly spaced values than would be returned if interpolation
was not applied.
By default, interpolated retrieval uses the interpolation setting specified for the tag in the AVEVA
Historian. This means that if a tag is set to use stair-step interpolation, interpolated retrieval gives the
same results as cyclic retrieval.
Interpolation is only applied to analog tags. If you retrieve data for ot her types of tags, stair-step
interpolation is used, and the results are the same as for cyclic retrieval.
Interpolated retrieval is a bit slower than cyclic retrieval. It shares the lim itations of cyclic retrieval in that
it may not accurately represent the stored proc ess data.
Data is retrieved in interpolated mode with a start time of TC 0 and an end time of TC2. The resolution has
been set in such a way that the historian returns data for three cycle boundaries at TC 0, TC1, and TC2. P1
to P12 represent actual data points stored on the historian. Of these points, eleven represent normal
analog values, and one, P 7, represents a NULL value due to an I/O Server disconnect, which causes a
gap in the data between P 7 and P 8.
The green points (P 2, PC1, PC2) are returned. The yellow points (P 7, P11, P12) are used to interpolate the
returned value for each cycle. The red points are considered, but not used in calculating the points to
return.
Version 2020 37
AVEVA™ Historian Retrieval Guide Data Retrieval Options
Because P 2 is located exactly at the query start time, it is returned at that time without the need for any
interpolation. At the following cycle boundary, point PC1 is returned, which is the NULL value
represented by P 7 shifted forward to time TC1. At the last cycle boundary, point PC2 is returned, which
has been interpolated using points P 11 and P12.
You can use various parameters to adjust which values are returned in interpolated retrieval mode. For
more information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 89
Resolution (Values Spaced Every X ms) (wwResolution) on page 91
History Version (wwVersion) on page 102
Interpolation Type (wwInterpolationType) on page 103
TimeStamp Rule (wwTimeStampRule) on page 105
Qualit y Rule (wwQualit yRule) on page 109
To use the interpolated mode, set the following parameter in your query.
wwRetrievalMode = 'Interpolated'
38 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Version 2020 39
AVEVA™ Historian Retrieval Guide Data Retrieval Options
40 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
The sample data points and the res ults 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 preceding data point at 00:17 because the following data point at 00:22 is NULL. Because
a NULL value precedes the 00:30 cycle boundary at 00:29, the NULL is returned at the cycle boundary.
The value at 00:40 is an interpolation of the dat a points at 00:38 and 00:42.
A value is ret urned at the start time and end time of the query using interpolation of the surrounding
points.
When a NULL value precedes a cycle boundary, that NULL will be returned at t he cycle boundary.
If a valid value precedes a cycle boundary, but is followed by a NULL value aft er the cycle boundary, no
interpolation will be used and wwInterpolationTy pe will be set to STA IRS TEP for that value.
For the " best fit" retrieval mode, the total time for the query is divided into even sub-periods, and then up
to five values are ret urned for each sub -period:
First value in the period
Last value in the period
Minimum value in the period, with its actual time
Maximum value in the period, with its actual time
The first "exception" in the period (non-Good quality)
Version 2020 41
AVEVA™ Historian Retrieval Guide Data Retrieval Options
"Best fit" retrieval allows for a compromise between delt a ret rieval and cyclic retrieval. For example, delta
retrieval can accurat ely represent a process over a long period of time, as shown in the following trend.
However, to achieve this representation, a large number of data values must be returned.
If cyclic retrieval is used to retrieve the data, the retrieval is much more efficient, because fewer values
are returned. However, the representation is not as accurate, as the following trend shows.
42 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
"Best fit" retrieval allows for faster retrieval, as typically achieved by using cyclic retrieval, plus the better
representation typically achieved by using delt a retrieval. This is shown in the following trend.
For example, for one week of five-second data, 120,960 values would be returned for delta retrieval,
versus around 300 values for best-fit retrieval.
Best-fit retrieval uses retrieval cycles, but it is not a true cyclic mode. Apart from the initial value, it only
returns actual delta points. For example, if one point is both the first value and the minimum value in a
cycle, it is returned only one time. In a cycle where a tag has no points, nothing is returned.
As in cyclic retrieval, the number of cycles is based on the specified resolution or cycle count. However,
the number of values returned is likely to be more than one per cycle.
All points are returned in chronological order. If multiple points are to be ret urned for a particular
timestamp, then those points are returned in the order in which the corresponding tags were specified in
the query.
The best-fit algorithm is only applied to analog and analog summary tags. For all other tags, delta results
are returned.
The following illustration shows how the best-fit algorit hm selects points for an analog tag.
Version 2020 43
AVEVA™ Historian Retrieval Guide Data Retrieval Options
Data is retrieved in best-fit mode with a start time of TC0 and an end time of TC2. The res olution has been
set in such a way that the historian returns dat a for two complete cycles starting at TC0 and TC1 and an
incomplet e cycle starting at TC2. P1 to P 12 represent actual data points stored on the historian. Of these
points, eleven represent normal analog values, and one, P 7, represents a NULL value due to an I/O
Server disconnect, which causes a gap in the data between P 7 and P 8.
Because P 2 is located exactly at the start time, no initial value needs to be interpolated at the start time.
Therefore, point P 1 is not considered at all. All other points are considered, but only the points indicated
by green markers on the graph are returned.
From the first cycle, four points are returned:
P2 as the initial value of the query, as well as the first value in the cycle
P4 as the minimum value in the cycle
P6 as both the maximum value and the last value in the cycle
P7 as the first (and only) occurring exception in the cycle
From the second cycle, three points are returned:
P8 as the first value in the cycle
P9 as the maximum value in the cycle
P11 as both the minimum value and the last value in the cycle
As no exception occurs in the second cycle, none is returned.
Because the tag does not have a point exactly at the query end time, where an incomplete third cycle
starts, the end value P C2 is interpolated between P 11 and P12, assuming that linear interpolation is used.
You can use various parameters to adjust which values are returned in best-fit retrieval mode. For more
information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 89
Resolution (Values Spaced Every X ms) (wwR esolution) on page 91
History Version (wwVersion) on page 102
Interpolation Type (wwInterpolationType) on page 103
Qualit y Rule (wwQualit yRule) on page 109
wwRetrievalMode = 'BestFit'
For example, an analog tag is retrieved over a five-minute period using the best-fit retrieval mode. The
wwResolution parameter is set to 60000, thus specifying five 1-minute cycles. Within each cycle, the
retrieval sub-system returns the first, minimum, maximum, and last data points. There are no exception
(NULL) points in the time period. Notice how the points at the query start time and at the query end time
are interpolated, while all other points are actual delta points.
44 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
A point will be returned at the query start time and the query end time for each tag queried, if a point
exists for that tag at or after the end time of the query. The values of the initial and final points wi ll be
determined by interpolating the points prec eding and following the query start or query end time.
Standard interpolation rules will be used to return the initial and final values. For more information, see
Interpolated Retrieval on page 37.
Version 2020 45
AVEVA™ Historian Retrieval Guide Data Retrieval Options
When any of the four good points are returned from a cycle that contains gaps or from an incomplete
cycle with the query end time located inside of the calculation cycle the quality detail of each of the
non-null points returned is modified to alert the user to this fact. This is done by performing a logical OR
operation of the value 4096, which means partial cycle, onto the existing quality detail. (This is the delta
point equivalent to the use of PercentGood for cyclic.)
Average Retrieval
For the time-weighted average (in short: "average") retrieval mode, a time-weighted average algorit hm is
used to calculate the value to be returned for each retrieval cycle.
For a statistical average, the actual dat a values are used to calculat e the average. The average is the
sum of the data values divided by the number of dat a values. For t he following data values, the statistical
average is computed as:
(P1 + P 2 + P3 + P4) / 4) = Average
For a time-weighted average, values are multiplied by the time difference between the points to
determine the time-weighted value. Therefore, the longer a tag had a particular value, the more weight
that value holds in the overall average. The overall average is determined by adding all of the
time-weight ed values and then dividing that number by the total amount of time.
Which values are weighted depends on the interpolation setting of the tag. For a tag that uses linear
interpolation, the midpoints bet ween values are weighted. For a tag t hat uses stair -step interpolation, the
earlier of two values is weighted.
For the following dat a values of a tag that uses linear interpolation, the time-weighted average is
computed as:
46 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
(((P1 + P2) / 2) x (T2 - T1)) + (((P2 + P3) / 2) x (T3 - T2)) + (((P 3 + P4) / 2) x (T4 - T3)) / (T4 - T1) = Average
If the same tag uses stair-step interpolation, the time-weighted average is:
((P1 x (T2 - T1)) + (P 2 x (T3 - T2)) + (P 3 x (T4 - T3 ))) / (T4 - T1) = A verage
The SQL Server AVG aggregate is a simple statistical average. Using the average retrieval mo de wit h a
cycle count of 1 returns dat a much faster than the AVG aggregat e, and usually more accurately due to
the time weighting. The E vent subsystem also returns a simple statistical average.
A verage retrieval returns one row for each tag in the query fo r each cycle. The number of cycles is based
on the specified resolution or cycle count.
The time-weighted average algorithm is only applied to analog and analog summary tags. If you us e
average retrieval with other tags, the results are the same as when us ing regular cyclic retrieval.
The following illustration shows how the time-weighted average is calculated for an analog tag that uses
linear interpolation.
Data is retrieved in average mode wit h a start time of TC0 and an end time of TC2. The resolution has been
set in such a way that the historian returns dat a for two complete cycles starting at TC0 and TC1 and an
incomplet e cycle starting at TC2. P1 to P 9 represent actual data points stored on the historian. Of these
points, eight represent normal analog values, and one, P 5, represents a NULL due to an I/O S erver
disconnect, which causes a gap in the data between P 5 and P 6. Assume that the query calls for
timestamping at the end of the cycle.
Version 2020 47
AVEVA™ Historian Retrieval Guide Data Retrieval Options
You can use various parameters to adjust which values are returned in average retrieval mode. For more
information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 89
Resolution (Values Spaced Every X ms) (wwResolution) on page 91
History Version (wwVersion) on page 102
Interpolation Type (wwInterpolationType) on page 103
TimeStamp Rule (wwTimeStampRule) on page 105
Qualit y Rule (wwQualit yRule) on page 109
To use the average mode, set the following parameter in your query.
wwRetrievalMode = 'Average'
48 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Version 2020 49
AVEVA™ Historian Retrieval Guide Data Retrieval Options
AND wwCycleCount = 5
')
The results are:
If wwTimeStampRule = END, the initial value is calculated by performing an average calculation on the
cycle leading up to the query start time. No special handling is done for the final value.
If wwTimeStampRule = START, the final value is calculated by performing an average calculation on the
cycle following the query end time. No special handling is done for the initial value.
Gaps introduced by NULL values are not included in the average calculations. The average only
considers the time ranges with good values. TimeGood indicates the total time per cycle that the tags
value was good.
Minimum Retrieval
The minimum value retrieval mode returns the minimum value from the actual data values within a
retrieval cycle. If there are no actual data points stored on the historian for a given cycle, nothing is
returned. NULL is returned if the cycle contains one or more NULL values.
As in cyclic retrieval, the number of cycles is based on the specified resolution or cycle count. However,
minimum retrieval is not a true cyclic mode. Apart from the initial value, all points returned are delta
points.
Minimum retrieval only works with analog tags. For all other tags, normal delta results are returned.
All returned values are in chronological order. If multiple points are to be ret urned for a particular
timestamp, they are returned in the order in which the tags were specified in the query. If the minimum
value occurs several times in a cycle, the minimum value with the earliest timestamp is returned.
The minimum ret rieval mode must use the "<=" operator for the ending date/time.
Using the minimum retrieval mode with a cycle count of 1 returns the same results as the SQL Server
MIN aggregate; however, the data is returned much faster.
50 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
The following illustration shows how the minimum value is selected for an analog tag.
This example has a start time of TC0 and an end time of TC2. The resolution has been set in such a way
that the historian returns data for two complete cycles starting at TC0 and TC1, a "phantom" cycle starting
at TCP, and an incomplete cycle starting at TC2. The phantom cycle has the same duration as the first
cycle in the query period, extending back in time from the query start time.
For the queried tag, a total of 18 points are found throughout the cycles, represented by the markers P 1
through P 18. Of these points, 17 represent normal analog values. The point P 13 represents a NULL due to
an I/O Server disconnect, which causes a gap in the data between P 13 and P14.
The minimum value for the "phantom" cycle starting at TCP is returned as the initial value at TC0. Point P 18
is not considered at all because it is outside of the query time frame. All other points are considered, but
only the points indicated by green mark ers on the graph are returned (P 10, P13, and P 17).
In total, four points are returned:
P4 as the minimum value of the "phantom" cycle and the initial point
P10 as the minimum value in the first cycle
P13 as the first and only exception occurring in the first cycle
P17 as the minimum value in the second cycle
No points are returned for the incomplete third cycle starting at the query end time, because the tag does
not have a point exactly at that time.
If the minimum value of the first cycle is located exactly at the query start time, both this value and the
minimum value of the phantom cycle are returned.
You can use various parameters to adjust which values are returned in minimum retrieval mode. For
more information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 89
Resolution (Values Spaced Every X ms) (wwResolution) on page 91
History Version (wwVersion) on page 102
Qualit y Rule (wwQualit yRule) on page 109
Version 2020 51
AVEVA™ Historian Retrieval Guide Data Retrieval Options
To use the minimum mode, set the following parameter in your query:
wwRetrievalMode = 'Min'
or
wwRetrievalMode = 'Minimum'
52 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
For analog tags, the minimum value of the tag in the cycle leading up to the query start time is returned
with its timestamp changed to the query start time. If there is no point exactly at the "phantom" cycle start
time, the point leading up to the phantom cycle is also considered for the minimum calculation. (No
adjustments are made to the quality of the initial point even though the timestamp may have been
altered.) Apart from the initial value, all points returned are delta points. (For more information on initial
values, see Delta Retrieval - Initial Values on page 34.)
If a point occurs exactly on the query end time, that point will be returned with the partial cycle bit, 4096,
set in quality detail. If there is more than one such point, only the first point will be returned.
Version 2020 53
AVEVA™ Historian Retrieval Guide Data Retrieval Options
When a minimum value is returned from a cycle that contains gaps (including a gap extended from the
previous cycle) or from an incomplete cycle with the query end time loc ated inside of the calculation
cycle, the point’s quality detail is modified to flag this. This is done by performing a logical OR operation
of the value 4096, which indicat es a partial cycle, onto the existing quality detail.
As an example of how minimum retrieval mode handles NULLs, consider the following query:
54 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
The sample data points and the res ults 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. The resolution is set at 10,000 milliseconds.
Because there is no value that matches the start time, an initial value at 00:20 is returned based on the
minimum value of t he preceding cycle, which is the dat a point at 00:09. In t he two subs equent cycles, the
minimum values are at 00:22 and 00:38. The quality for thes e two values is set to 4288 (4096 + 192). The
remaining data points are excluded because they are not minimums. In addition, the fi rst NULL at 00:28
is included, but the second NULL (at 00:29) is not.
Maximum Retrieval
The maximum value retrieval mode returns the maximum value from the actual dat a values within a
retrieval cycle. If there are no actual data points stored on the historian for a given cycle, nothing is
returned. NULL is returned if the cycle contains one or more NULL values.
As in cyclic retrieval, the number of cycles is based on the specified resolution or cycle count. However,
maximum ret rieval is not a true cyclic mode. Apart from the initial value, all points returned are delta
points.
Maximum ret rieval only works with analog tags. For all ot her tags, normal delta results are returned.
All returned values are in chronological order. If multiple points are to be ret urned for a particular
timestamp, they are returned in the order in which the tags were specified in the query. If the maximum
value occurs several times in a cycle, the maximum value with the earliest timestamp is returned.
The maximum retrieval mode must use the "<=" operat or for the ending date/time.
Using the maximum ret rieval mode wit h a cycle count of 1 returns the same res ults as the SQL Server
MA X aggregate; however, the data is returned much faster.
The following illustration shows how the maximum value is selected for an analog tag.
This example has a start time of TC0 and an end time of TC2. The resolution has been set in such a way
that the historian returns data for two complete cycles starting at TC0 and TC1, a "phantom" cycle starting
at TCP, and an incomplete cycle starting at TC2. The phantom cycle has the same duration as the first
cycle in the query period, extending back in time from the query start time.
For the queried tag, a total of 18 points are found throughout the cycles, represented by the markers P 1
through P 18. Of these points, 17 represent normal analog values. The point P 13 represents a NULL due to
an I/O Server disconnect, which causes a gap in the data between P 13 and P14.
Version 2020 55
AVEVA™ Historian Retrieval Guide Data Retrieval Options
The maximum value for the "phantom" cycle starting at TCP is returned as the initial value at TC0. Point P 18
is not considered at all because it is outside of the query time frame. All other points are considered, but
only the points indicated by green mark ers on the graph are returned (P 12, P13, and P 15).
In total, four points are returned:
P6 as the maximum value of the "phantom" cycle and the initial point
P12 as the maximum value in the first cycle
P13 as the first and only exception occurring in the first cycle
P15 as the maximum value in the second cycle
No points are returned for the incomplete third cycle starting at the query end time, because the tag does
not have a point exactly at that time.
If the maximum value of the first cycle is located exactly at the query start time, this value and the
maximum value of the phantom cycle are returned.
You can use various parameters to adjust which values are returned in maximum retrieval mode. For
more information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 89
Resolution (Values Spaced Every X ms) (wwResolution) on page 91
History Version (wwVersion) on page 102
Qualit y Rule (wwQualit yRule) on page 109
To use the maximum mode, set the following parameter in your query:
wwRetrievalMode = 'Max'
or
wwRetrievalMode = 'Maximum'
56 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Version 2020 57
AVEVA™ Historian Retrieval Guide Data Retrieval Options
For analog tags, the maximum value of the tag in the cycle leading up to the query start time is returned
with its timestamp changed to the query start time. If there is no point exactly at the phant om cycle st art
time, the point leading up to the phantom cycle is also considered for the maximum calculation. No
adjustments are made to the quality of the initial point even though the timestamp may have been
altered. Apart from the initial value, all points returned are delta points. (For more information on initial
values, see Determining Cycle Boundaries on page 140.)
If a point occurs exactly on the query end time, that point is returned with the partial cycle bit, 4096, set in
quality detail. If there is more than one such point, only the first point is returned.
58 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
The sample data points and the res ults 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. The resolution is set at 10,000 milliseconds.
Because there is no value that matches the start time, an initial value at 00:20 is returned based on the
maximum value of the prec eding cycle, which is the data point at 00:15. In the two subsequent cycles,
the maximum values are at 00:26 and 00:35. The quality for these t wo values is set to 4288 (4096 + 192).
The remaining data points are excluded because they are not maximums. In addition, the first NULL at
00:28 is included, but the second NULL (at 00:29) is not.
Integral Retrieval
Integral retrieval calculates the values at retrieval cycle boundaries by integrating t he graph described by
the points stored for the tag. Therefore, it works much like average retrieval, but it additionally applies a
scaling factor. This retrieval mode is useful for calculating volume for a particular t ag. For ex ample, if one
of your tags represents product flow in gallons per second, integral retrieval allows you to retrieve the
total product flow in gallons during a certain time period.
Integral retrieval is a true cyclic mode. It returns one row for each tag in the query for each cycle. The
number of cycles is based on the specified resolution or cycle count.
Version 2020 59
AVEVA™ Historian Retrieval Guide Data Retrieval Options
Integral retrieval only works with analog tags. For all other tags, normal cyclic results are returned.
You can use various paramet ers to adjust which values are returned in integral retrieval mode. For more
information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 89
Resolution (Values Spaced Every X ms) (wwResolution) on page 91
History Version (wwVersion) on page 102
Interpolation Type (wwInterpolationType) on page 103
TimeStamp Rule (wwTimeStampRule) on page 105
Qualit y Rule (wwQualit yRule) on page 109
wwRetrievalMode = 'Integral'
In this example, the integral is computed for each of five 1 -minut e long cycles. The wwQualityRule
parameter is used to ensure that only points with good quality are used in the computation, which means
that points with doubt ful quality are discarded. The rules used to determine the returned OPCQuality are
the same as described for a time weighted average query.
60 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Also, the "phantom" cycle affects the integral ret rieval mode just as it does the average retrieval mode.
For examples, see Querying Aggregate Data in Different Ways on page 169.
If wwTimeStampRule = END, the initial value is calculated by performing an integral calculation on the
cycle leading up to the query start time. No special handling is done for the final value.
If wwTimeStampRule = START, the final value is calculated by performing an integral calculation on the
cycle following the query end time. No special handling is done for the initial value.
Gaps introduced by NULL values are not included in the integral calculations. The average only
considers the time ranges with good values. TimeGood indicates the total time per cycle that the tags
value was good.
Slope Retrieval
Slope retrieval returns the slope of a line drawn through a given point and the point immediately before it,
thus expressing the rate at which values change.
This retrieval mode is useful for detecting if a tag is changing at too great a rate. For example, you might
have a temperature that should steadily rise and fall by a small amount, and a sharp inc rease or
decrease could point to a potential problem.
The slope retrieval mode can be considered a delta mode. Apart from the initial value and a value at the
query end time, all returned points are calculated delta points returned with the timestamp of an actual
delta point.
Slope retrieval only works with analog tags. For all other tags, normal delta results are returned.
All returned values are in chronological order. If multiple points are to be ret urned for a particular
timestamp, they are returned in the order in which the tags were specified in the query.
Version 2020 61
AVEVA™ Historian Retrieval Guide Data Retrieval Options
You can use various parameters to adjust which values are returned in slope retrieval mode. For more
information, see the following sections:
History Version (wwVersion) on page 102
Qualit y Rule (wwQualit yRule) on page 109
wwRetrievalMode = 'Slope'
62 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
For example, the following query calculates and returns the rate of change of the ReactTemp tag in
°C/second. The initial value in the Quality column at the query start time shows no value is located
exactly at that time, so the slope returned is the same as the one ret urned at the next delta point. (For
more information on initial values, see Determining Cycle Boundaries on page 140.)
At 08:01:17.947 t he tag has two delta points, so a slope is calculat ed and retu rned for t he first point, while
a NULL is returned at the second one with a special QualityDetail of 17, indicating that no slope can be
calculated as it is either plus or minus infinite.
An initial value is always generated. If a point is stored exactly at the query start time, the slope is
returned as the slope between that point and the previous point. Otherwise, the slope is calculated using
the slope of the points before and after the query start time.
A final value is always generat ed. If a point is stored exactly at the query end time, the slope is returned
as the slope between that point and the previous point. Otherwise, the slope is calculated using the slope
of the points before and after the query end time.
Version 2020 63
AVEVA™ Historian Retrieval Guide Data Retrieval Options
The first NULL following a non-NULL value is returned. Subsequent NULL values are not. If a point is
preceded by a NULL, the slope for that point will be zero.
Counter Retrieval
Counter retrieval allows you to accurately retrieve the delta change of a tag’s value over a period of time
even for tags that are reset upon reaching a "rollover value." The rollover value is defined in the AVEVA
Historian for eac h tag.
This retrieval mode is useful for determining how much of an item was produced during a particular time
period. For example, you might have an integer counter that keeps track of how many cartons were
produced. The counter has an indic ator like this:
The next value after the highest value that can be physically shown by the counter is called the rollover
value. In this example, the rollover value is 10,000. When the counter reaches the 9,999th value, the
counter rolls back to 0. Therefore, a count er value of 9,900 at one time and a value of 100 at a later time
means that you have produc ed 200 units during that period, even though the counter value has dropped
by 9,800 (9,900 minus 100). Counter retrieval allows you to handle this situation and receive the correct
value. For each cycle, the counter retrieval mode shows the increase in that counter during the cycle,
including rollovers.
Note: If Historian receives a data tag value that is outside of the specified engineering unit boundaries,
Historian ignores the received value and instead returns a 0. For example, if a value can be an integer
between 1 and 8, and the received value is 9, Historian returns 0 as the value for that tag during that
cycle.
Counter retrieval also works with floating point counters, which is useful for flow meter data. Similar to the
carton counter, some flow meters "roll over" after a certain amount of flow accumulates. For both
examples, the need is to convert the accumulating measure to a "delt a change" value over a given
period.
Counter retrieval is a true cyclic mode. It returns one row for each tag in the query for each cycle. The
number of cycles is based on the specified resolution or cycle count.
The counter algorithm is only applied to analog tags and to discrete tags. For integer analog tags, the
result will be an integer returned as a float data type. For a real analog tag, the rollover value and the
result may be real values and can include fractional values. If a query contains tags of other types, then
no rows are returned for those tags. For discrete tags, the rollover value is assumed to be 2.
The rules used to determine the OP CQuality returned with a counter value are the same as for a time
weighted average query. For more information, see Quality Rule (wwQualityRule) on page 109. When a
rollover has occurred in the calculation cycle, a special quality detail of 212 is returned in all non -NULL
cases.
CTU c ounters will default to "signed integer" tags when imported into the Historian, giving a normal range
of -2147483648 to 2147483647 (for a 32-bit integer). In operation, these counters will count up to the
upper limit and "rollover" to the lower limit on the next increment. If thes e tags are changed to be
"unsigned integers" the normal range will be 0 to 4294967295 and values will rollover to "0", conforming
to the expected behavior of a tag used with "count er" retrieval. When used with a 16 -bit CTU count er, the
same rules apply, but the range of values is -32768 to 32767 as "signed" and 0 to 65535 for an
"unsigned".
64 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
The following illustration shows how the counter algorithm determines the count for an analog tag.
This example has a start time of TC0 and an end time of TC3. The resolution has been set in such a way
that the historian returns dat a for three complete cycles starting at TC0, TC1, and TC2, and an incomplete
cycle starting at TC3.
For the queried tag, a total of twelve points are found throughout the cycles repr esented by the markers
P1 through P 12. Of these points, eleven represent normal analog values. The point P 9 repres ents a NULL
due to an I/O Server disconnect, which causes a gap in the data between P 9 and P 10. Point P 12 is not
considered because it is outside of the query time frame.
All points are considered in the counter calculation, but only the yellow ones are actually used to
determine which values to return to the client. The returned points are P C0, PC1, PC2 and PC3, shown in
green at the top to indicate that there is no simple relationship between them and any of the actual points.
All cycle values are calculat ed as the delta change between the cycle time in question and the previous
cycle time, taking into account the number of rollovers between the t wo points in time. The counter
algorithm assumes that a rollover occurred if the current value is lower than the previous value. The initial
value at the query start time (P C1) is calculated the same way, only based on a phant om cycle before the
query start time.
For example, the formula to calculate P C1 is as follows:
PC1 = n * VR + P6 - P1
where:
n = the number of rollovers that have occurred during the cycle
VR = the rollover value for the tag
If either n or VR are equal to zero, P C1 is simply the difference bet ween the values P 1 and P6.
In the case of cycle C2, there is no value at the cycle time, so the NULL value represented by point P 9 is
returned. In the case of cycle C3, a NULL is again returned, bec ause there is no counter valu e at the
previous cycle boundary to use in the calculation. There must be a full cycle of values in order for the
counter to be calculated.
If a gap is fully contained inside a cycle, and if points occur within t he cycle on both sides of the gap, then
a counter value is returned, even though it may occasionally be erroneous. Zero or one rollovers are
assumed, even though the counter might have rolled over multiple times.
Version 2020 65
AVEVA™ Historian Retrieval Guide Data Retrieval Options
If you have a counter that you typically reset manually before it rolls over, you must set the rollover value
for the tag to 0 so that the count is simply how much change occurred since the manual reset.
For example, assume that you have the following data values for five consecutive cycle boundaries, and
that the value 0 occurs as the first value within the last cycle:
100, 110, 117, 123, 3
If you set the rollover value to 0, the counter retrieval mode assumes that the 0 following the value 123
represents a manual reset, and returns a value of 3 for the last cycle, which is assumed to be the count
after the manual reset. The value 0 itself does not contribute 1 to the counter value in this case.
If the rollover value is instead set to 200, then the counter ret rieval mode assumes that the value 0
represents a normal rollover, and a count of 80 is calculated and returned (200 - 123 + 3). In this case,
the value 0 contributes 1 to the counter value, and t hat is the change from the value 199 to the value 200.
You can set a deadband for counter retrieval to better handle reporting of rat es and quantities. For
example, setting a counter deadband can help to:
Distinguish between counter resets and rollovers.
Filter out counter reversals.
The counter deadband is the percentage of the full range of the counter.
For example, if you set the counter deadband to be 10, then any counter reset that occurs within the top
10% of the range is assumed to be a rollove r and is counted as such.
For a reversal, you might have a conveyor belt carrying boxes that are counted as they pass by a station.
If a jam occurs, you might reverse the conveyor belt to clear it, resulting in the counter decrementing and
then incrementing again. In this case, a counter deadband of 10 would discard any duplicate counts
within 10% of the range starting from the point of reversal. Only one reversal can be det ected until the
rollover occurs.
You can use various paramet ers to adjust which values are returned in integral retrieval mode. For more
information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount ) on page 89
Resolution (Values Spaced Every X ms) (wwResolution) on page 91
History Version (wwVersion) on page 102
TimeStamp Rule (wwTimeStampRule) on page 105
Qualit y Rule (wwQualit yRule) on page 109
An initial value is returned using the period leading up to the query start time.
A data point that has a cycle time is used to generate the counter value for its preceding cycle. A NULL
point with cycle time will cause the preceding cycle to end in a gap and the following cycle to start with a
gap.
66 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
If wwQualityRule is configured as OP TIMIS TIC, NULL data points will not be used in calculation. 0.0 will
be used as the starting base value for the query unless the query data starts with a NULL. If the query
starts with a NULL, the value change for the cycle is calculated from the first actual value in the cycle,
rather than 0.
Otherwise, if any points considered in a cycle have UNCE RTAIN quality, the result for that row will also
have UNCERTA IN quality. Any cycle that starts or ends in a ga p will have a quality detail of 65536.
The quality detail of DOUB TFUL will be used with the counter result for the cycles, if a NULL point is
considered for the cycle and the counter result is not NULL.
If the configured rollover value is larger than 0.0, then the data points whose values are greater than or
equal to the rollover value causes the counter value for the cycle to be set to 0.0, with
qdIO_FILTERE DPOINT applied to the quality detail.
Similarly, if any data point with a value less than 0.0 is found in a cycle, the counter value for the cycle is
set to 0.0, with qdIO_FILTE RE DPOINT applied to the quality detail.
wwRetrievalMode = 'Counter'
In the following example, the rollover value for the SysTimeS ec system tag is set to 0. In a two-minute
time span, the SysTimeS ec tag increments from 0 to 59 two times. The following query returns the total
count within the two-minute time span, which begins with Start Time and ends with Dat eTime. The
QualityDetail of 212 indicates that a count er rollover occurred during the query time range.
ValueState Retrieval
ValueState retrieval returns information on how long a tag has been in a particular value state during
each ret rieval cycle. That is, a time-in-state calculation is applied to the tag value.
Version 2020 67
AVEVA™ Historian Retrieval Guide Data Retrieval Options
This retrieval mode is useful for determining how long a machine has been running or stopped, how
much time a process spent in a particular state, how long a valve has been open or closed, and so on.
For example, you might have a steam valve that releases steam int o a reactor, and you want to know the
average amount of time the valve was in the open position during the last hour. ValueState retrieval can
return the short est, longest, average, or total time a tag spent in a state, or the time spent in a state as a
percentage of the total cycle length.
When you use ValueState retrieval for a tag in a trend chart, you must specify a single value state for
which to retrieve information. ValueState retrieval then returns one value for each cycle—for example,
the total amount of time that the valve was in the "open" state durin g each 1-hour cycle. This information
is suitable for trend display.
If you don’t specify a state, ValueState retrieval returns one row of information for each value that the tag
was in during each cycle. For example, this would return not only the time a valve was in the "open" state,
but also the time it was in the "closed" state. This information is not suitable for meaningful display in a
regular trend. You can, however, retrieve this type of information in a query and view it as a table.
ValueState ret rieval works with integer, discrete, string, and state summary tags. For other types of tags,
no rows are returned. NULL values are treated like any other distinct state.
The values returned at the query start time are the result of applying the algorithm to a "phantom" cycle
preceding the query range. It is assumed that the tag value at the start of t he cycle is located at that point
in time.
To specify the type of calculation, set the wwStateCalc parameter in the query. For more information, see
State Calculation (wwStateCalc ) on page 117.
Value
ValueState Retrieval
C0 C1 C2 C3
PC0 PC1 PC2 PC3
ON
OFF Gap
1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29
Time
TC0 TC1 TC2 TC3
This example has a start time of TC0 and an end time of TC3. The resolution has been set in such a way
that the historian returns dat a for three complete cycles starting at TC0, TC1, and TC2, and an incomplete
cycle starting at TC3. Time is measured seconds.
A gap in the data occurs in the third cycle due to an I/O Server disconnect.
The state calculation is based on each cycle, and the values returned at the query start time are not
regular initial values, but are the resulting values that occur after applying the algorithm to the last cycle
preceding the query range. The returned points are P C0, PC1, PC2 and PC3, shown in green at the top to
indicate that there is no simple relationship between the calculated values and any of the actual points.
Assume the query is set so that the total time (wwStateCalc = ‘Total’)in the two states are returned. The
timestamping is set to use the cycle end time.
For TC0, the query ret urns t wo rows (one for the "on" state and one for the "off" state), calculated as a
result of the "phantom" cycle that precedes the query start time. The values have a timestamp of the
query start time.
68 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
For TC1, one row is returned for the "on" state. The "on" state occ urred twice during the cycle--one
time for four seconds and again for two seconds before the cycle boundary, and the total time
returned is six seconds. The state was "off" twice during the cycle for a total time of four seconds,
and one row is returned wit h that value.
For TC2, one row is returned for the "on" state, and one row is returned for the "off" state. The "on"
state occurred for a total of nine seconds between the cycle boundaries, and the "off" state occurred
for a total of one second.
For TC3, one row is returned for the "on" state, and one row is returned for the "off" state. The "on"
state occurred for a total of four seconds between the cycle boundaries, and the "off" state occurred
for a total of three seconds. An additional row is returned for the NULL state occurring as a result of
the I/O Server disconnect.
Using the same data, if you queried the total contained time for the states, the following is returned:
For TC0, the query ret urns t wo values (one for the " on" state and one for the "o ff" state), calculated as
a result of the "phantom" cycle the precedes the query start time. The value has a timestamp of the
query start time.
For TC1, one row is returned for the "on" state, and one row is returned for the "off" state. The "on"
state occurred one time for four seconds within the cycle. The two seconds of "on" time that crosses
the cycle boundary does not contribute t o the t otal time. The state was "off" one time during the cycle
for two seconds completely within the cycle boundary.
For TC2, the state was not "on" for any contained time between the cycle. Both occurrences of the
"on" state cross over a cycle boundary, so no rows are returned for this state. One row is returned for
the "off" state. The state was "off" one time during the cyc le for one seconds completely within the
cycle boundary.
For TC3, one row is returned for the "on" state, and one row is returned for the "off" state. The state
was "on" for a single contained time of two seconds bet ween the cycle boundaries. The state was
"off" three times during the cycle for three seconds completely within the cycle boundary. An
additional row is returned for the NULL state occurring as a result of the I/O Server disconnect. The
state was NULL for a total of three seconds. The I/O Server disconnect that "disrupted" the off state
is treated as its own state, thereby changing what would have been a single "off" state instance of
five seconds into two instances of the "off" state for one second each.
You can use various parameters to adjust which values are returned in ValueState retrieval mode. For
more information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 89
Resolution (Values Spaced Every X ms) (wwResolution) on page 91
History Version (wwVersion) on page 102
TimeStamp Rule (wwTimeStampRule) on page 105
Qualit y Rule (wwQualit yRule) on page 109
State Calculation (wwStateCalc ) on page 117
wwRetrievalMode = 'ValueState'
Version 2020 69
AVEVA™ Historian Retrieval Guide Data Retrieval Options
To specify the type of aggregation, set the wwStat eCalc parameter in the query, such as:
wwStateCalc = 'Total'
Be sure that you use the "<=" operator for ending date/time.
For examples, see the following:
ValueState Retrieval Query 1: Minimum Time in State on page 70
ValueState Retrieval Query 2: Minimum Time in State for a Single Tag on page 70
ValueState Retrieval Query 3 on page 71
ValueState Retrieval Query 4 on page 71
ValueState Retrieval Query 5 on page 72
ValueState Retrieval Query 6: Querying State Summary Values on page 72
70 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Version 2020 71
AVEVA™ Historian Retrieval Guide Data Retrieval Options
72 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
For example, this can occur if SysTimeSec is summarized with a state summary with one minute
resolution, but then queried with 10 second int ervals. In most of the retrieval cy cles, there will be no
values, but in the cycle that includes the summary end time (one in six of the ret rieval cycles), all 60
states would be returned with each state having a state time of 1 second for a total of 60 s econds of state
time in a 10 second retrieval cycle.
The values returned at the query start time are the result of applying the algorithm to the last cycle
preceding the query range.
NULLs are considered a state and are reported along with the other states.
RoundTrip Retrieval
RoundTrip retrieval is very similar to ValueState retrieval in that it performs calculations on state
occurrences in the within a cycle period you specify. However, ValueState retrieval uses the time spent in
a certain state for the calculation, and RoundTrip retrieval uses the time bet ween consecutive leading
edges of the same state for its calculations.
You can use the RoundTrip retrieval mode for increasing the efficiency of a process. For example, if a
process produces one item per cycle, then you would want to minimize the time lapse between two
consecutive cycles.
The RoundTrip mode returns a row for each state in any given cycle. RoundTrip retrieval only works with
integer analog tags, discrete tags, and string tags. If real analog tags are specified in the query, then no
rows are returned for these tags. RoundTrip retrieval is not applied to state s ummary or analog summary
tags. NULL values are treated as any other distinct value and are used to analyze the round trip for
disturbances.
RoundTrip retrieval is supported for the History and StateWideHistory tables.
Any point on the boundary of the end cycle will be considered to the next cycle. The point on the
boundary of the end query range is not counted in the calculation except that it is used to indicat e that the
previous state is a contained state.
If no roundtrip state is found within the cycle for a supported tag, a NULL StateTime value is returned. If
there is no valid point prior to the phantom cycle, a NULL state is returned for the phantom cycle.
Version 2020 73
AVEVA™ Historian Retrieval Guide Data Retrieval Options
The following illustration shows how RoundTrip retrieval returns values for a discret e tag.
Value
RoundTrip Retrieval
C0 C1 C2 C3
PC0 Round-trip PC1 PC2 PC3
ON
OFF Gap
Round-trip
1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29
Time
TC0 TC1 TC2 TC3
This example has a start time of TC0 and an end time of TC3. The resolution has been set in such a way
that the historian returns dat a for three complete cycles starting at TC0, TC1, and TC2, and an incomplete
cycle starting at TC3. Time is measured seconds.
A gap in the data occurs in the third cycle due to an I/O Server disconnect.
The state calculation is based on each cycle, and the values returned at the query start time are not
regular initial values, but are the resulting values that occur after applying the algorithm to the last cyc le
preceding the query range. The returned points are P C0, PC1, PC2 and PC3, shown in green at the top to
indicate that there is no simple relationship between the calculated values and any of the actual points.
Assume the query is set so that the total contained time in t he two states are returned. The timestamping
is set to use the cycle end time. The RoundTrip ret rieval mode returns values for states that are
completely contained within the cycle boundaries. Th e following is returned:
For TC0, the query ret urns t wo values (one for the " on" state and one for the "off" state), calculated as
a result of the "phantom" cycle that preceeds the query start time. The value has a timestamp of the
query start time.
For TC1, one row is returned for the "on" state, and one row is returned for the "off" state. The
round-trip for the " on" state occurred one time for four seconds completely wit hin the cycle boundary.
The round-trip for the "off" state occurred one time during the cycle for five seconds.
For TC2, a round-trip did not occur for either state within the cycle boundaries. One NULL row is
returned for this cycle.
For TC3, one row is returned for the "on" state, and one row is returned for the "off" state. The state
was "on" for a single contained time of two seconds bet ween the cycle boundaries. The state was
"off" one time during the cycle for one second completely within the cycle boundary. An additional
row is ret urned for the NULL state occurring as a result of the I/O Server disconnect.
For TC3, one row is returned for the "on" state, and one row is returned for the "off" state. The state
was "on" for a single contained time of three seconds between the cycle boundaries. One row is
returned for the "off" state for a total cont ained time of seven seconds. (The first round-t rip for the
"off" state includes the I/O Server disconnect for a length of four seconds. The second round-trip has
a length of three seconds.) An additional row is returned for the NULL state occurring as a result of
the I/O Server disconnect, and the returned value is NULL because there is no round-trip during the
cycle for it. The I/O S erver disconnect that "disrupted" the off state is treated as its own state, thereby
changing what would have been a single "off" state instance of five seconds into t wo instances of the
"off" state for one second eac h.
74 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
You can use various parameters to adjust the values that must be ret urned in the Ro undTrip retrieval
mode. For more information, see the following sections:
TimeStamp Rule (wwTimeStampRule) on page 105
Qualit y Rule (wwQualit yRule) on page 109
State Calculation (wwStateCalc ) on page 117
wwRetrievalMode = ‘RoundTrip’
The following queries compare the res ults between ValueState retrieval and RoundTrip retrieval.
This first ValueState retrieval query returns the average amount of time that the 'Reactor1OutletValve'
tag is in "on" state and the average amount of time it is in the "off" state for a single cycle. Any state
changes that occur across the cycle boundaries are not included.
The first two rows are for the "phant om" cycle leading up to the query start time and have a timestamp of
the query start time.
The second two rows show t he average amount of time for each state and have a timestamp of t he query
end time (the default).
Compare these results to same basic query that instead uses RoundTrip ret rieval:
Version 2020 75
AVEVA™ Historian Retrieval Guide Data Retrieval Options
The values returned at the query start time are the result of applying the algorithm to the last cycle
preceding the query range.
Like in the ValueState ret rieval mode, the NULL state is treated as a valid distinct value. This allows you
to analyze round trips for disturbances.
Option Results
None Returns all rows that successfully meet the criteria; no edge detection is implemented
at the specified resolution.
Leading Returns only rows that are the first to successfully meet the criteria (ret urn true) after a
row did not successfully meet the criteria (returned false).
Trailing Returns only rows that are the first to fail the criteria (return false) after a row
successfully met the criteria (returned true).
Both All rows satisfying both the leading and trailing conditions are returned.
76 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Edge detection only applies to analog and discrete value detectors. Also, edge detection is handled
slightly differently based on whether you are using analog tags or discret e tags.
You can also use the ToDiscrete() query filter to determine when data values cross a particular threshold.
For more information, see Converting Analog Values to Discrete Values (ToDiscrete) on page 120.
For more information on event detection with the Classic Event subsystem, see Classic Event
Subsystem in the AVEVA Historian Supplemental Guide.
For example, the behavior of the WHE RE clause as it processes a result set can be illustrated as:
D F
B
V
A
L
U
E
A C E G
TIME
Slopes A-B, C-D and E-F are rising edges, while slopes B-C, D-E and F-G are falling edges. The slopes
are affected by the WHERE clause, which is a combination of the wwEdgeDetection option and the
comparis on operator us ed against the value.
The following table describes the rows that would be returned for the various edge detection settings:
Leading Falling and Falling edge Rising edge Falling edge Rising edge
rising edges; only; first only; first only; first only; first
first value that value to meet value to meet value to meet value to meet
meets the the criteria.* the criteria. the criteria. * the criteria.
criteria.
Trailing Falling and Rising edge Falling edge Rising edge Falling edge
rising edges; only; equal to only; first only; first only; first
first value to the first value value to fail value to fail value to fail
fail the criteria to fail the the criteria.* the criteria. the criteria.*
after a value criteria.
meets the
criteria.
* If the falling edge is a vertical edge with no slope, the query will return the lowest value of that edge.
The following query selects all values of "SysTimeS ec" that are great er than or equal to 50 from the
History table between 10:00 and 10:02 a.m. on December 2, 2001. No edge det ection is specified.
Version 2020 77
AVEVA™ Historian Retrieval Guide Data Retrieval Options
DateTime Value
2001-12-02 10:00:50.000 50
2001-12-02 10:00:52.000 52
2001-12-02 10:00:54.000 54
2001-12-02 10:00:56.000 56
2001-12-02 10:00:58.000 58
2001-12-02 10:01:50.000 50
2001-12-02 10:01:52.000 52
2001-12-02 10:01:54.000 54
2001-12-02 10:01:56.000 56
2001-12-02 10:01:58.000 58
If Leading is specified as the paramet er in the edge detection time domain extension, the only rows in the
result set are those that are the first to successfully meet the WHERE clause criteria (returned true) after
a row did not successfully meet the WHERE clause criteria (returned false).
The following query selects the first values of "SysTimeSec" from the History table to meet the Value
criterion between 10:00 and 10:02 a.m. on December 2, 2001.
DateTime Value
2001-12-02 10:00:50.000 50
2001-12-02 10:01:50.000 50
78 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Analog Tags on page 77. Notice that even though the original query returned ten rows, the edge
detection only returns the first row recorded aft er the event criteria returned true.
If Trailing is specified as the parameter in the edge detection extension, the only rows in the res ult set are
those that are the first to fail the criteria in the WHERE claus e (returned false) after a row successfully
met the WHERE clause criteria (returned true).
The following query selects the first values of "SysTimeSec" from the History table to fail the Value
criterion between 10:00 and 10:02 a.m. on December 2, 2001.
DateTime Value
2001-12-02 10:01:00.000 0
2001-12-02 10:02:00.000 0
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Analog Tags on page 77. Notice that even though the original query returned ten recorded rows for each
value, the edge detection only returns the first row recorded after the event criteria returned false.
If Both is specified as the parameter in the edge detection extension, all rows satisfying both the le ading
and trailing conditions are returned.
The following query selects values of "SysTimeS ec" from the History table that meet bot h the Leading
and Trailing criteria between 10:00 and 10:02 a.m. on December 2, 2001.
Version 2020 79
AVEVA™ Historian Retrieval Guide Data Retrieval Options
DateTime Value
2001-12-02 10:00:50.000 50
2001-12-02 10:01:00.000 0
2001-12-02 10:01:50.000 50
2001-12-02 10:02:00.000 0
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Analog Tags on page 77. Notice that value of the first row in the original query is returned in the result set.
Tag Description
The following queries select values of "SysPulse" and "MyPulse" that have a value of 1 (On) from the
History and WideHistory tables between 12: 59 and 1:04 a.m. on December 8, 2001. No edge detection is
specified.
This is a query of the History table:
80 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
If Leading is specified as the paramet er in the edge detection time domain extension, the only rows in the
result set are those that are the first to successfully meet the WHERE clause criteria (returned true) after
a row did not successfully meet the WHERE clause criteria (returned false).
The following queries select values of "SysPulse" and "MyPulse" that have a value of 1 (On) from the
History and WideHistory tables between 12:59 and 1:04 a.m. on December 8, 2001.
This example queries the History table, if the WHE RE clause criteria specify to return only discrete
values equal to 1 (On), then applying a leading edge detection does not change the result set.
Version 2020 81
AVEVA™ Historian Retrieval Guide Data Retrieval Options
This example queries the WideHistory table, applying a leading edge detection requires that the
condition only evaluate to true if both values are equal to 1 (On).
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Discrete Tags on page 80. 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.
If Trailing is specified as the parameter in the edge detection extension, the only rows in the res ult set are
those that are the first to fail the criteria in the WHERE claus e (returned false) after a row successfully
met the WHERE clause criteria (returned true).
This example queries the History table. If the WHERE claus e criteria specifies ret urning 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).
82 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
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).
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Discrete Tags on page 80. 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.
If Both is specified as the parameter in the edge detection extension, all rows satisfying both the leading
and trailing conditions are returned.
The following queries select values of "SysPulse" and "MyPulse" that meet an edge detection of Both for
a value criterion of 1 (On) from the History and WideHistory tables between 12:59 and 1:04 a.m. on
December 8, 2001.
Version 2020 83
AVEVA™ Historian Retrieval Guide Data Retrieval Options
Compare these results with the same query using no edge detection, as shown in the Edge Detection for
Discrete Tags on page 80.
Predictive Filter
AVEVA Historian supports predictive retrieval. Beginning with AVEVA Historian 2014 R2 Patch 01, the
historian can return predictive data based on a "simple linear regression" (SLR) algorithm. More
capabilities will be added in fut ure releases.
84 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
With AVEVA Historian, you can create a query based on dat a you have stored to predict additional
values in a trend. Historian returns predictive data based on a "simple linear regression" (S LR) algorithm.
For example, based on your currently stored values, you could use the predictive ret rieval feature to help
predict if a certain production target will be met by the end of the shift. Or, if the Historian loses
communication with the dat a source, you could use predictive retrieval to determine whether and when a
tank is likely to become empty.
You can predict:
Values in bet ween other values.
Values that extend beyond stored values.
For example, suppose you already captured data for a tag with timestamps up to 3 p.m. on a certain day,
but not for the rest of the shift, which ran until 5 p.m., because of a power cut. With predictive retrieval,
you can view the int erpolated results base d bet ween 3 p.m. and 5 p.m. These results are based on the
data you received through 3 p.m.
The following is an example of a query that retrieves stored values and reports both those values and
additional predictive dat a:
Version 2020 85
AVEVA™ Historian Retrieval Guide Data Retrieval Options
In this case, Historian retrieves the first point on or before the dat etime requested in the query. The line
(TC0) is the timestamp for which the start bound point is requested. P 1 is returned because that is the start
or first point for the query date time.
Historian can also use bounding value retrieval to return an end bound point, as in the following
illustration:
In this case, Historian returns first point aft er the datetime requested in the query. TC0 is the timestamp for
which the end bound point is requested and P 3 is returned as the ending bound point because this is the
first point after the query dat e time.
wwRetrievalMode = 'StartBound'
To return an end bound point, set the following parameter in your query.
wwRetrievalMode = 'EndBound'
Example 1 - Retrieve start bound point
select DateTime,TagName,Value
where TagName 'Plant2.R31.BatchNum'
and wwRetrievalMode = 'StartBound'
and DateTime >= '2019-04-24 12:00:00'
86 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
In all retrieval modes, you can adjust which values the historian returns by specifying retrieval options.
The retrieval options are implement ed as special parameters that you set as part of the retrieval query.
This section explains each of these options. For an overview of which options apply to which retrieval
modes, see Which Options Apply to Which Retrieval Modes? on page 87.
Interpolation Type
on page 105
on page 99
page 118
page 95
102
109
117
Cyclic Retrieval on page Y Y Y Y* Y Y Y
27
Delta Retrieval on page Y Y Y Y Y Y Y
30
Interpolated Retrieval on Y Y Y Y Y Y Y Y
page 37
Best Fit Retrieval (see Y Y Y Y Y Y Y Y
"Best Fit Retrieval" on
page 41)
Average Ret rieval on Y Y Y Y Y Y Y Y
page 46
Minimum Retrieval on Y Y Y Y Y Y
page 50
Maximum Retrieval on Y Y Y Y Y Y
page 55
Integral Retrieval on page Y Y Y Y Y Y Y Y
59
Version 2020 87
AVEVA™ Historian Retrieval Guide Data Retrieval Options
Interpolation Type
on page 105
on page 99
page 118
page 95
102
109
117
Slope Retrieval on page Y Y Y Y
61
Counter Retrieval on Y Y Y Y Y Y
page 64
ValueState Retrieval on Y Y Y Y Y Y Y
page 67
RoundTrip Retrieval on Y Y Y Y Y Y Y
page 73
Bounding Values
Retrieval (see "Bounding
Value Retrieval" on page
85)
* - only on AVEVA Historian 9.0 and later
** - only AVEVA Historian 2014 R2 P01 and later
Note: The wwP arameters extension is reserved for future use. The wwRowCount parameter is still
supported, but is deprec ated in favor of wwCycleCount.
The extensions are implemented as "virtual" columns in the extension tables. When you query an
extension table, you can specify values for these column parameters to manipulate the dat a that will be
returned. You will need to specify any real-time extension parameters each time that you execute the
query.
For example, you could specify a value for the wwResolution column in the query so that a resolution is
applied to the returned data set:
88 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Because the extension tables provide additional functionality that is not possible in a normal SQL S erver,
certain limitations apply to the Transact-SQL supported by these tables. For more information, see
Unsupported or Limited Syntax Options on page 18.
Although the Microsoft SQL Server may be configured to be case-sensitive, the values for the virtual
columns in the extension tables are always case-insensitive.
Note: You cannot use the IN clause or OR clause to specify more than one condition for a time domain
extension. For example, "wwVersion IN ('original', 'latest')" and "wwRetrievalMode =
'Delta' OR wwVersion = 'latest'" are not supported.
For general information on creating SQL queries, see your Microsoft SQL Server documentation.
In retrieval modes that use cycles, the cycle count determines the number of cycles for which dat a is
retrieved. The number of actual return values is not always identical with this cycle count. In "truly cyclic"
modes (Cyclic, Interpolated, A verage, and Integral), a single data point is returned for every cycle
boundary. However, in other cycle-based modes (Best Fit, Minimum, Maximum, Counter, ValueState,
and RoundTrip), multiple or no data points may be returned for a cycle, depending on the nature of the
data.
The length of eac h cycle (the "resolution" of the returned values) is calculated as follows:
DC = DQ / (n – 1)
Where DC is the length of the cycle, DQ is the duration of the query, and n is the cycle count.
Instead of specifying a cycle count, you can specify the resolution. In that case, the cycle count is
calculated based on the res olution and the query duration. For more information, see Resolution (Values
Spaced E very X ms) (wwResolution) on page 91.
This option is relevant in the following retrieval modes:
Cyclic Retrieval on page 27
Interpolated Retrieval on page 37
"Best Fit" Retrieval (see "Best Fit Retrieval" on page 41)
Average Ret rieval on page 46
Minimum Retrieval on page 50
Maximum Retrieval on page 55
Integral Retrieval on page 59
Counter Retrieval on page 64
ValueState Retrieval on page 67
RoundTrip Retrieval on page 73
The application of the cycle count also depends on whether you are querying a wide table. If you are
querying the History table, the cycle count determines the number of rows returned per tag. For example,
a query that applies a cycle count of 20 to two tags will ret urn 40 rows of data (20 rows for each tag). If
you are querying a WideHistory table, the cycle count specifies the total number of rows to be ret urned,
regardless of how many tags were queried. For example, a query that applies a cycle count of 20 to two
tags returns 20 rows of data.
Values chosen:
If wwRes olution and wwCycleCount are not specified, then a default of 100 cycles are chosen.
Version 2020 89
AVEVA™ Historian Retrieval Guide Data Retrieval Options
If wwRes olution and wwCycleCount are set to 0, then a default of 100000 cycles are chosen.
If wwRes olution and wwCycleCount are both set, then wwCycleCount is ignored.
If wwCycleCount is specified and is less than 0, then a default of 100 cycles are chosen.
For ValueState retrieval, if the start time of the cycle is excluded, no st ates are returned for the first
cycle.
For ValueState retrieval, if the end time of the cycle is excluded, no states are returned for the last
cycle.
90 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Notice that the values of the two tags are mixed together in the same column.
Note: The rowset is guaranteed to contain one row for eac h tag in the normalized query at every
resolution interval, regardless of whether a physical row exists in history at that particular instance in
time. The value cont ained in the row is the last known phy sical value in history, at that instant, for the
relevant tag.
Instead of specifying a resolution, you can specify the cycle count directly. In that case, the resolution is
calculated based on the cycle count and the query duration. For more information, see Cycle Count (X
Values over Equal Time Intervals) (wwCycleCount) on page 89.
This option is relevant in the following retrieval modes:
Cyclic Retrieval on page 27
Version 2020 91
AVEVA™ Historian Retrieval Guide Data Retrieval Options
...
92 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Simple use of phantom Cycle s not defined, but similar simple Phantom cycle used to calculate
cycle use of time before query start time aggregates
Integral
Counter
ValueState
RoundTrip
It’s common to expect a single aggregate row returned for a particular time interval. You can accomplish
this in several ways.
The following example is querying for hourly averages. It returns a single row time stamped at the query
start time. If the query included the query end point by including an equal sign for it, the query would also
have ret urned an additional row at the query end time.
What may be confusing in this example is the calculation of the average in the returned row for the
phantom cycle leading up to the query start time. The query specifies a positive one hour time interval
between the query start time and the query end time. You may therefore expect that the calculated and
returned average should be for the specified interval.
Version 2020 93
AVEVA™ Historian Retrieval Guide Data Retrieval Options
However, the time difference bet ween start and end time in the above query is not actually required
because the resolution is provided explicitly (wwResolution = 36000000). If the query specified an end
time equal to the specified start time and if it included the equal sign for the end time, the query would still
return the same single row of data.
This second example also asks for hourly averages and it also returns only a single row of data stamped
at the query start time. This query, however, must specify a time difference between the start and end
time, because the resolution is not explicitly defined in the query.
As in the preceding query, the specified interval and cycle count of 1 may look like the returned row has
been calculated for the speci fied int erval, but the returned row is once again for the phantom cycle
leading up to the start time.
For some queries, you may want to be certain to include values on a cycle boundary. For example, the
following query is looking for a minimum value wit hin a cycle. In this query, the beginning DateTime
statement uses ">=" to ensure that the entire cycle is queried. E ven if the minimum value happens to be
at the beginning of the cycle, the following query will provide an accurate res ult:
SELECT StartDateTime, *
FROM History
WHERE TagName = 'SysTimeSec'
AND DateTime >= '2016-03-31 15:41:10'
AND DateTime < '2016-03-31 15:41:20'
AND wwRetrievalMode = 'Min'
AND Quality <> 133
AND wwCycleCount = 1
The StartDateTime makes it easier to see which time interval was used to calculate the returned
aggregate. This column returns the time stamp of the beginning of the cycle used for the aggregat e
calculation. The time stamp is always returned in accordance with the specified time zone and always
has the s ame offset as the time stamp returned in t he DateTime column, even when the two time stamps
are on different sides of a DS T change.
Assuming results are timestamped at the end of the cycle (as is done by default when
wwTimeStampRule is set to END), the initial rows in the examples above would return a DateTime equal
to '2009-10-16 08:00:00', and the StartDateTime column would return '2009 -10-16 07:00:00' making it
easy to interpret the res ult.
If instead the query were to ask for results time stamped at the beginning of the cycle with
wwTimeStampRule set to STA RT, the initial rows in the same examples would still return a DateTime
equal to '2009-10-16 08:00:00', but the time stamp has now been shifted in accor dance with the time
stamp request. The result is therefore calculated for the specified time int erval between 8 a.m. and 9 a.m.
In this example, the new StartDateTime column would ret urn the same time stamp as the DateTime
column, '2009-10-16 08:00:00', again making it easier to interpret the result.
94 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
For retrieval modes for which cycles are defined, the StartDateTime column ret urns the cycle start time.
These modes are:
Cyclic Retrieval on page 27
Interpolated Retrieval on page 37
"Best Fit" Retrieval (see "Best Fit Retrieval" on page 41)
Average Ret rieval on page 46
Minimum Retrieval on page 50
Maximum Retrieval on page 55
Integral Retrieval on page 59
Counter Retrieval on page 64
ValueState Retrieval on page 67
RoundTrip Retrieval on page 73
In the remaining retrieval modes, the StartDat eTime column ret urns the same time stamp as the
DateTime column.
For an additional ex ample, see Querying Aggregat e Data in Different Ways on page 169.
Version 2020 95
AVEVA™ Historian Retrieval Guide Data Retrieval Options
Data is retrieved for t he time period starting with TS and ending with TE. All points in the graphic represent
data values stored on the historian. The gray areas represent the time deadband, which starts anew with
every returned value. Only the green points (P 2, P4, P7, P8, P9, P11) are returned. The ot her points are not
returned because they fall within a deadband.
Note: All of these example queries return dat a values for the analog tag 'SysTimeSec'.
96 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Version 2020 97
AVEVA™ Historian Retrieval Guide Data Retrieval Options
98 Version 2020
Data Retrieval Options AVEVA™ Historian Retrieval Guide
Data is retrieved for t he time period starting with TS and ending with TE. All points in the graphic represent
data values stored on the historian. The gray areas represent the value deadband, whic h starts anew
with every returned value. Only the green points (P 2, P5, P6, P7, P9, P10, P11) are returned. The other
points are not ret urned because they fall within a deadband.
Note: Each of these ex amples returns data values for the analog tag 'Sys TimeSec '. The minimum
engineering unit for 'Sys TimeS ec' is 0, and the maximum engineering unit is 59.
Version 2020 99
AVEVA™ Historian Retrieval Guide Data Retrieval Options
DateTime Value
2001-12-09 11:35:00.000 0
2001-12-09 11:35:06.000 6
2001-12-09 11:35:12.000 12
2001-12-09 11:35:18.000 18
2001-12-09 11:35:24.000 24
2001-12-09 11:35:30.000 30
2001-12-09 11:35:36.000 36
2001-12-09 11:35:42.000 42
2001-12-09 11:35:48.000 48
2001-12-09 11:35:54.000 54
2001-12-09 11:36:00.000 0
2001-12-09 11:36:06.000 6
2001-12-09 11:36:12.000 12
2001-12-09 11:36:18.000 18
2001-12-09 11:36:24.000 24
2001-12-09 11:36:30.000 30
2001-12-09 11:36:36.000 36
2001-12-09 11:36:42.000 42
2001-12-09 11:36:48.000 48
2001-12-09 11:36:54.000 54
2001-12-09 11:37:00.000 0
DateTime Value
2001-12-09 11:35:00.000 0
2001-12-09 11:35:03.000 3
2001-12-09 11:35:06.000 6
2001-12-09 11:35:09.000 9
2001-12-09 11:35:12.000 12
2001-12-09 11:35:15.000 15
2001-12-09 11:35:18.000 18
2001-12-09 11:35:21.000 21
2001-12-09 11:35:24.000 24
2001-12-09 11:35:27.000 27
2001-12-09 11:35:30.000 30
2001-12-09 11:35:33.000 33
2001-12-09 11:35:36.000 36
2001-12-09 11:35:39.000 39
2001-12-09 11:35:42.000 42
2001-12-09 11:35:45.000 45
2001-12-09 11:35:48.000 48
2001-12-09 11:35:51.000 51
2001-12-09 11:35:54.000 54
2001-12-09 11:35:57.000 57
2001-12-09 11:36:00.000 0
2001-12-09 11:36:03.000 3
2001-12-09 11:36:06.000 6
2001-12-09 11:36:09.000 9
2001-12-09 11:36:12.000 12
2001-12-09 11:36:15.000 15
2001-12-09 11:36:18.000 18
2001-12-09 11:36:21.000 21
2001-12-09 11:36:24.000 24
2001-12-09 11:36:27.000 27
2001-12-09 11:36:30.000 30
2001-12-09 11:36:33.000 33
2001-12-09 11:36:36.000 36
2001-12-09 11:36:39.000 39
2001-12-09 11:36:42.000 42
2001-12-09 11:36:45.000 45
2001-12-09 11:36:48.000 48
2001-12-09 11:36:51.000 51
2001-12-09 11:36:54.000 54
2001-12-09 11:36:57.000 57
2001-12-09 11:37:00.000 0
When ret rieving the latest version, the wwVersion parameter always returns with a value of LA TES T for
all values, even though many of the values may actually be the original values that came from the I/O
Server. To distinguish between an actual latest value and an original value, a special QualityDetail of 202
is returned for a good, latest point.
For example:
Stairstep: No int erpolation occurs. The value at the cycle boundary is assumed to be the same
value as the last stored value before the cycle boundary. The last known point is returned with the
given cycle time. If no valid value can be found, a NULL is ret urned.
Linear: The historian calculates a new value at the cycle boundary by interpolating between the last
stored value before the boundary and the first stored value aft er the boundary. If either of these
values is NULL, it returns the last stored value before the boundary.
Expressed as a formula, V c is calculated as:
Vc = V1 + ((V2 - V1) * ((Tc - T1) / (T2 - T1)))
The type of data that you want to retrieve usually determines the interpolation type to use. For example ,
if you have a thermocouple, the temperature change is linear, so it’s best to use linear interpolation. If you
have a tag that contains discrete measurements, such as a set point, then you probably want to use
stair-stepped values. In general, it is recommended that you use linear interpolation as the general
setting, and use stair-stepped values for the exceptions.
This option is relevant in the following retrieval modes:
-old-Interpolated Retrieval
"Best Fit" Retrieval
Average Ret rieval on page 46
Integral Retrieval on page 59
The quality of an interpolated point is determined by the wwQualityRule setting. For more information,
see Qualit y Rule (wwQualityRule) on page 109.
o At TC2: The last value in the "phant om" cycle starting at TC2
End: The value for a given cycle is stamped with the cycle end time. For ex ample, in the following
illustration of a cyclic query, the following values are returned at the cycle boundaries:
o At TC0: P1, because it is the last value in the "phantom" cycle ending at TC0. Because the End
timestamp rule is used, the value is timestamped at TC0.
o At TC1: P7, because it falls on the cycle boundary. In cyclic mode, if there is a value right on the
cycle boundary, it is considered to belong to the cycle before the boundary. In this case, this is
the cycle starting at TC0 and ending at TC1, and because the End timestamp rule is used, the
value is timestamped at TC1.
o At TC2: P11, because it is the last value in the cycle ending at TC2
Server default: Either Start or End is used, depending on the system parameter setting on the
AVEVA Historian.
This option is relevant in the following retrieval modes:
Cyclic Retrieval on page 27 (AVEVA Historian 9. 0 and later)
Interpolated Retrieval on page 37
Average Ret rieval on page 46
Integral Retrieval on page 59
A quality rule of GOOD means that data values with uncertain (64) OPC quality are not used in the
retrieval calculations and are ignored. Values with bad QualityDetail indicat e gaps in the data.
A quality rule of E XTE NDED means that data values with both good and uncert ain OP C quality are
used in the retrieval calculations. Values with bad QualityDetail indicate gaps in the data.
A quality rule of OP TIMIS TIC means that calculations that include some good and some NULL
values do not cause the overall calculations to return NULL.
You can apply a quality rule to all retrieval modes.
The OP TIMIS TIC setting for the quality rule lets you retrieve information that is possibly incomplete but
may nevertheless provide better results where the calculation cycle contains data gaps. This setting
calculates using the last known good value prior to the gap (if possible). The logic for determining the
quality of the points returned remains unchanged. The integral retrieval mode is an exception to this
where the integral is scaled up to cover gaps. For more information, see Integral Retrieval on page 59.
The following figure shows a counter retrieval situation in which three of the four shown cycle boundaries
are locat ed in data gaps. Without using OP TIMIS TIC, counter queries would return a NULL at all cycle
boundaries because the mode needs valid good values at each end of the cycle calculate a precise
differenc e.
If the query were to specify OPTIMIS TIC, the counter mode will always return rows with numeric counter
values and good quality. These rows may or may not be precise. The PercentGood column of the row
returns the percentage of time in each cycle in which retrieval was able to find values stored with good
quality, so if the PercentGood is anything less than 100, then the returned row may be incorrect. Quality
is returned as uncertain if percent good is not 100 percent.
Now look at the count er values that are returned using OP TIMIS TIC quality in the preceding illustration.
The query skips the value to be returned at the first cycle boundary, because there is not enough
information about the cycle prior to that boundary. At the second cycle boundary, the value 0 will be
returned, because there was a gap in the data for the entire first cycle. In the second cycle, there are two
points, P1 and P2. The query uses P2 as the end value of the cycle and infers a start value of the cycle
from P1. At the third cycle boundary, Tc2, the query returns P2 – P1. Similarly, at the last cycle boundary,
the query returns P4 – P3.
For the integral retrieval mode, the query does not summarize data for gaps because there is no way to
know which value to use for the summariz ation. However, if the query specifies OPTIMIS TIC quality, the
query uses the last known good value for the summarization in the gap. As described for the counter
retrieval example, the PercentGood column also expresses the quality of the calculated value in integral
retrieval, so if the PercentGood is anything less than 100, then the returned row may be incorrect.
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:
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:
Note: Cyclic, Full, Delta, Maximum, Minimum, and BestFit do not have combined qualities; therefore,
the rules are not applied to these modes..
The nature of the data and how you set the cycle count determines whet her you should use a "contained"
version of the aggregation. The calculations apply to each unique value state that the tag was in during
each retrieval cycle for the query. The total and percent calculations are always exact, but the minimum,
maximum, and average calculations are subject to "arbitrary" cycle boundaries that do not coincide with
the value changes. Therefore, non-intuitive res ults may be returned. This is most apparent for
slowly-changing tags queried over long cycles.
For example, a string tag that assumes only two distinct values changing every 10 minutes is queried
with a cycle time of two hours. Going into a cycle, the value (state) at the cycle boundary is recorded. If
the value then changes a short while into the cycle, the state found at the cycle start time will most likely
end up being the minimum value. Likewise, the state at the cycle end time is cut short at the cycle end
time. The two cut-off occurrenc es in turn skew the average calculation.
For RoundTrip retrieval, you can only specify the following types of state calculations (aggregations) to
be performed on the data. The calculations are for eac h unique state within each retrieval cycle for the
query.
MinContained. The shortest time span between consecutive leading edges of any state that occurs
multiple times within the cycle, while disregarding state occurrences that are not fully contained
inside of the cycle.
MaxContained. The longest time span between consecutive leading edges of any state that occurs
multiple times within the cycle, while disregarding state occurrences that are not fully contained
inside of the cycle.
AvgContained. The average time span bet ween consecutive leading edges of any state that occurs
multiple times within the cycle, while disregarding state occurrences that are not fully contained
inside of the cycle. (This is the default.)
TotalContained. The total time span bet ween consecutive leading edges of any state that oc curs
multiple times wit hin the cycle while disregarding state occurrences that are not fully contained inside
of the cycle.
PercentContained. The percentage of the cycle time spent in time span between cons ecutive
leading edges for a state that occurs multiple times within the cycle while disregarding value
occurrences that are not fully contained inside of the cycle.
This analog filter removes outliers from a set of analog points based on the assumption that the
distribution of point values in the set is a normal distribution.
The following illustration shows an example of outliers.
You can filter outliers by specifying a filter called ‘SigmaLimit()’. This filter has one parameter defined for
specifying the value of n. This parameter is of type double. If the parameter is omitted, then a default
parameter of 2.0 is used.
When this filter is specified in any retrieval mode, a time weighted mean, ì (mu), and time weighted
standard deviation, ó (sigma), are found for each analog tag for the entire query range including phantom
cycles if any, and points falling outside of the range [ì - nó, ì + nó] are removed from the point set before
the points are processed furt her. In other words, the value will be filtered out if value > ì + nó or value < ì
– nó.
Time weighted standard deviation is calculated as:
Math.Sqrt( (integralOfSquares - 2 * timeWeightedA verage * integral + totalTime * timeWeightedA verage
* timeWeightedA verage)/totalTime);
This is the single pass equivalent to the formula:
Ranges where the value is NULL are excluded from these calculations.
A cyclic query example using a ‘SigmaLimit()’ filter without specifying the n value would look like this:
If the first value would be filtered out by the SigmaLimit filter, the value will be replaced with the time
weighted mean.
The analog to discrete conversion filter allows you to conve rt value streams for any analog tag in the
query tag list into discrete value streams. The filter can be used with all the retrieval modes.
To convert analog values to discrete values, specify the ToDiscrete() filter in the wwFilter column. This
filter has two parameters:
The values returned in the StateTime column show that the shortest amount of time that SysTimeSec
had values equivalent to either ON or OFF and remained in that state was 30 seconds. A similar
RoundTrip query would look like this:
The values returned in the StateTime column now show that the longest amount of time found between
roundtrips for both the OFF and the ON state within the 2-hour cycles was 60 seconds.
Using the ToDiscrete() filter is similar to using edge det ection for event tags. Edge detection returns
the actual value with a timestamp in history for when a value matched a certain criteria. The
ToDiscrete() filter returns either a 1 or 0 to show that the criteria threshold was crossed. The
ToDiscrete() filter is more flexible, however, in the following ways:
You can use it with delta and full retrieval.
You can combine it with "time-in-state" calculations to determine how long a value is above a certain
threshold or the duration between thres hold times.
Use the ToDiscrete() filt er if you are mostly interested in when something occurred, and not necessaril y
the exact value of the event.
For more information on edge detection, see Edge Detection for Events (wwEdgeDetection) on page 76.
This analog filter lets you force values in a well-defined range around one or more base values to "snap
to" that base value. For example, you can use this filter when a tank is known to be empty, but the tag
that stores the tank level returns a "noisy" value close to zero.
The filter can be used with all retrieval modes, but its main benefits are in the aggregat e retrieval modes:
average, integral, minimum, and maximum.
To zero values around the base value, specify the SnapTo() filter in the wwFilter column of the query.
The syntax for this filter is:
SnapTo([tolerance[,base_value_1[, base_value_2]…]])
This filter has two parameters:
BaseValue zero, one, or up to 100 comma-separated double single base value of 0.0
values
AUTO The retrieval mode determines the The retrieval mode determines the
value. See the following table for how timestamp. See the following table
AUTO applies to the value selection. for how AUTO applies to the value
This is the default value. selection. This is the default value.
FIRS T The first value that occurs within the The actual timestamp of the first
summary period. value occurrenc e within the
summary period.
LAST The last value that occurs within the The actual timestamp of the last
summary period. value occurrenc e within the
summary period.
MIN or MINIMUM The first minimum value that occurs The actual timestamp of the first
within the summary period. minimum value occurrence within
the summary period.
MA X or MA XIMUM The first maximum value that occurs The actual timestamp of the first
within the summary period. maximum value occurrence wit hin
the summary period.
AVG or AVERAGE A time-weighted average calculated The summary period start time.
from values within the summary
period.
INTE GRA L An integral value calculated from The summary period start time.
values within the summary period.
STDDEV or A standard deviation calculated from The summary period start time.
STA NDA RDDEV IA TION values within the summary period.
The following table describes the value to be considered if the value selector is set to AUTO:
Cyclic The last value within the summary period is used. The actual timestamp of the last
value occurrenc e within the summary period is used.
Delta The last value within the summary period is used. The actual timestamp of the last
value occurrenc e within the summary period is used.
Full The last value within the summary period is used. The actual timestamp of the last
value occurrenc e within the summary period is used.
Interpolated The retrieval mode determines the appropriate value t o ret urn. See the following table
for how AUTO applies to the value selection. This is the default value.
Best Fit The first, last, min, and max points from analog summaries are all considered as
analog input points. Best fit analysis is done with these points. If the analog summary
percentage good is not 100%, the cycle is considered to have a NULL.
A verage The averages of analog summaries are calculated using the values from the A verage
column of the AnalogS ummaryHistory table. Interpolation type is ignored for analog
summary values, and S TAIRS TEP interpolation is always used. PercentGood is
calculated by considering the TimeGood of each analog summary.
If cycle boundaries do not exactly match the summary periods of the stored analog
summaries, the averages and time good are calculat ed by prorating the average and
time good values for the portion of the time the summary period overlaps with the
cycle. Quality will be set to 64 (uncert ain) if cycle boundaries do not m atch summary
periods.
If the QualityDetail of any analog summary considered for a cycle is uncertain (64),
the resulting quality is set to 64.
Minimum The first minimum value within the summary period is used. The actual timestamp of
the first minimum value occurrence within the summary period is used.
Maximum The first maximum value within the summary period is used. The actual timestamp of
the first maximum value occurrenc e within the summary period is used.
Integral The integrals of analog summaries are calculated using the Integral column of the
AnalogSummaryHistory table. Interpolation type is ignored for analog summary
values, and S TA IRS TEP interpolation is always used. PercentGood is calculated by
considering the TimeGood of each analog summary.
If cycle boundaries do not exactly match the summary periods of the stored analog
summaries, the integrals and time good are calculated by prorating the integral and
time good values for the portion of the time the summary period overlaps with the
cycle. Quality is set to 64 (uncertain) if cycle boundaries do not match summary
periods.
If the QualityDetail of any analog summary considered for a cycle is uncertain (64),
the resulting quality will be set to 64.
Slope The last value within the summary period is used. The actual timestamp of the last
value occurrenc e within the summary period is used.
ValueState Cannot be used with analog summary dat a. No values are returned.
Counter Cannot be used with analog summary dat a. No values are returned.
RoundTrip Cannot be used with analog summary dat a. No values are returned.
For an analog summary tag, if any of the data within a summary period has an OP CQuality other than
Good, the OPCQuality returned will be Uncertain. This is true even for summary values that are not
calculated, such as first, last, minimum, maximum, and so on. For example, if the OPCQuality for a last
value is actually Good, but there was a I/O Server disconnect during the summary calculation period, the
OPCQuality for the last value is returned as Uncertain. A QualityDetail of 202 is used to distinguish
between the original point and the latest point.
C HAPTER 3
SQL Query Examples
In addition to query examples that use the AVEVA Historian time domain extensions, other query
examples are provided to demonstrate how to perform more complex queries or to further explain how
retrieval works.
The examples provided are not exhaustive of all possible database queries, but they should give you an
idea of the kinds of queries that you could write.
For general information on creating SQL queries, see your Microsoft SQL Server documentation.
Note: If you have configured SQL Server to be case -sensitive, be sure that you use the correct case
when writing queries.
Note: In certain situations, data can by pass the Live table. These situations include:
- Receiving non-streamed original data (store/forward or CSV);
- Receiving revision data for a Latest value;
- Receiving no new streamed values after Historian was shut down and disabled, or after the computer
was rebooted.
For more information, see History Tables and Views in the AVEVA Historian Database Ref erence.
The following query returns the current value of the specified tag. The query uses the remot e table view
(Live is used in plac e of INS QL.Runtime.dbo. Live).
TagName Value
ReactLevel 1145.0
(1 row(s) affected)
In the WideHistory table, the column type is determined by the tag type.
The following query returns values for three tags from the WideHistory table. "MyTagName" is a tag that
periodically is invalid.
2001-05-12 13:00:55.000 55 00 1
2001-05-12 13:00:56.000 56 00 1
2001-05-12 13:00:57.000 57 00 1
2001-05-12 13:00:57.500 57 00 null
2001-05-12 13:00:58.000 58 00 null
2001-05-12 13:00:59.000 59 00 null
2001-05-12 13:01:00.000 00 01 null
2001-05-12 13:01:00.500 00 01 2
2001-05-12 13:01:01.000 01 01 2
2001-05-12 13:01:02.000 02 01 2
2001-05-12 13:01:03.000 03 01 2
...
Notice that 57 appears twice since the occurrence of 1 changing to NULL for tag "MyTagName" occurs
sometime bet ween the 57th and 58t h second. The same applies for NULL changing to 2. The same
behavior applies to discrete values.
Note: When querying the AnalogSummary History view, a data point occuring at the same timestamp as
the EndDateTime is not considered part of the query interval. Instead, it is treated as the first data point
in the next interval beginning at EndDateTime, and so is not included in the maximum or average value
calculations.
The following query returns the minimum time in state, the minimum contained time in state, and value
for the SysTimeS ec system tag.
SELECT
TagName,
StartDateTime,
EndDateTime,
StateTimeMin as STM,
StateTimeMinContained as STMC,
Value
FROM StateSummaryHistory
WHERE TagName='SysTimeSec'
AND wwRetrievalMode='Cyclic'
AND wwResolution=5000
AND StartDateTime>='2009-10-21 17:40:00.123'
AND StartDateTime<='2009-10-21 17:40:05.000'
The results are:
Using SliceBy
You can retrieve summary statistics for a tag per batch by using the SliceBy parameter in a query.
Batches can be defined by changes in a different tag, such as a batch ID or valve position.
For example, suppose you wanted statistics on flow rate depending on the position of a valve. Each time
the valve position changes, a new batch is reported. Here is a query to retrieve that information:
This query uses the same data. This time, using SliceByValue, the query retrieves statistics on the flow
rate, but only for those batches when the valve is open.
where TagName='M31.FlowIn'
and SliceBy='M31.ValveIn'
and SliceByValue=1
and StartDateTime>='2018-11-27 0:00'
and EndDateTime<='2018-11-28 0:00'
2018-11-28 04:31:33
Note: This example correctly calculates the overall average for each state in the "A verage" column by
weighting the duration of each state. As explained by Simpson’s Paradox, the simpler, "A vgOfA vg"
calculation is not statistically accurate and can differ significantly with some data sets.
In a SQL query against a wide table, unconventional tag names must be delimited with brackets ( [ ] ),
because the tagname is used as a column name. For example, tagnames containing a minus ( - ) or a
forward slash ( / ) must be delimited, otherwise the parser will attempt to perform the corresponding
arithmetic operation. No error will result from using brackets where not strictly necessary. For more
information on unconventional tagnames, see Tag Naming Conventions.
The following is an example of how to delimit a tagname in a query on a wide table. "ReactTemp-2" and
"React Temp+2" are tagnames. Without the delimiters, the parser would attempt to include the " -2" and
"+2" suffixes on the tagnames as part of the arithmetic operation.
For clarity and maintainability of your queries, however, it is recommended that you do not use special
characters in tagnames unless strictly necessary.
Instead of using " … WHERE TagName IN (SELECT TagName … ) ", it is more efficient to use INNE R
REMOTE JOIN syntax.
In general, use the following pattern for INNE R REMOTE JOIN queries against the historian:
<SQLServerTable> INNER REMOTE JOIN <HistorianExtensionTable>
This query returns data from the history table, based on a string tag that you filter for from the StringTag
table:
This query returns data from the history table, based on a discrete tag that you filter for from the Tag
table:
The tag selected, ReactTemp, has a MinE U value of 0 and a MaxEU value of 220. Thus, the value
deadband will be 5 percent of (220 - 0), which equals 11. React Temp changes rapidly between its
extreme values, but the value remains constant for short periods near the high and low temperature
limits. Therefore, when changes are rapid, the value deadband condition is satisfied first, then the time
deadband is satisfied. In this region, the behavior is dominated by the time deadband, and the returned
rows are spaced at 5 second intervals. Where the temperature is more constant (particularly at the low
temperature end), the time deadband is satisfied first, followed by the value deadband. Both deadbands
are satisfied only when the value of a row is more than 11 degrees different from the previous row. Thus,
the effect of value deadband can be seen to dominate near the low and high temperature extremes of the
tag.
The results are:
Retrieval
Mode Resolution Cycle Count Results
CYCLIC N 0 (or no All stored data for tags during the specified time interval
value) are queried, and then a resolution of N ms applied.
CYCLIC 0 (or no value) 0 The server will return 100,000 rows per tag specified.
CYCLIC 0 (or no value) N All stored data for tags during the specified time interval
are queried, and then a cycle count of N evenly spaced
rows is applied.
CYCLIC N (any value is All stored data for tags during the specified time interval
ignored) are queried, and then a resolution of N ms applied.
CYCLIC (no value) (no value or a The server will return 100 rows per tag specified.
value less
than 0)
DELTA (any value is 0 All values that changed during the specified time interval
ignored) are returned (up to 100, 000 rows total).
DELTA (any value is N Values that changed during the specified time interval
ignored) are queried, and then a cycle count (first N rows) is
applied. The cycle count limits the maximum number of
rows returned, regardless of how many tags were
queried. For example, a query that applies a cycle count
of 20 to four tags will return a maximum of 20 rows of
data. An initial row will be returned for eac h tag, and the
remaining 16 rows will be based on subsequent value
changes for any tag.
DELTA (any value is (no value) All values that changed during the specified time interval
ignored) are returned (no row limit).
In general, if there is an error in the virt ual columns, or an unresolvable conflict, then zero rows are
returned.
Cycle boundaries are calculated based on the query start and end times, wwCycleCount, and
wwResolution.
If you only specify wwCycleCount, evenly spaced cycles are returned based on the value of
wwCycleCount.
If you only specify wwResolution, cycles are spaced wwResolution milliseconds apart starting at the
query start time until query end time is reached. The last cycle will have whatever duration is required to
end exactly at the query end time. If this last duration is shortened by this rule, it is known as a partial
cycle. Because of this, the final cycle duration may not match wwResolution.
If both wwCycleCount and wwResolution are specified, no result rows will be returned. If you specify
neither wwCycleCount nor wwResolution in the query, the query will return 100 rows.
Unless otherwise specified, a value is considered in a given full or partial cycle if its timestamp occurs at
or after the cycle start (timestamp >= cycle start) and before the cycle end (timestamp < cycle end).
For any query, the SQL Server performs all date/time computations in local server time, reformulates the
query with specific dates, and sends it on to the AVEVA Historian OLE DB provider. The AVEVA
Historian OLE DB provider then applies the wwTimeZone parameter in determining the result set.
For example, the following query requests the last 30 minutes of data, expressed in Eastern Daylight
Time (EDT). The server is located in the P acific Daylight Time (PDT) zone.
If it is currently 14: 00:00 in the P acific Daylight Time zone, then it is 17:00: 00 in the Eastern Daylight Time
zone. You would expect the query to return data from 16: 30:00 to 17:00: 00 E DT, representing the last 30
minutes in the Eastern Daylight Time zone.
However, the data that is returned is from 13:30:00 to 17:00:00 EDT. This is because the SQL Server
computes the "DateAdd(mi, -30, GetDate())" part of the query assuming the local server time
zone (in this example, PDT). It then passes the AVEVA Historian OLE DB provider a query similar to the
following:
Because the OLE DB provider is not provided an end date, it assumes the end date to be the current time
in the specified time zone, which is 17:00: 00 EDT.
SysTimeSec 59.0
SELECT count(*)
FROM History
WHERE TagName = 'SysTimeSec'
AND DateTime >= '2001-12-20 0:00'
AND DateTime <= '2001-12-20 0:05'
AND wwRetrievalMode = 'delta'
AND Value >= 30
150
If you use the OPENQUE RY function, you cannot perform arithmetic functions on t he COUNT(*) column.
However, you can perform the count outside of the OPENQUE RY, as follows:
10801 5400
(1 row(s) affected)
...
If you use a math operator, such as plus (+), minus (-), multiply (*), or divide (/), you will need to add a
blank space in front of and after the operator. For example, "Value - 2" instead of "Value-2".
Thus, for delta retrieval mode, a SUM or AVG is applied only if the value has changed from the previous
row.
If you perform an AVG in delta retrieval mode, AVG will be computed as:
SUM of delta values/number of delta values
For example, an AVG is applied to all of the returned column values:
SysTimeMin SysTimeSec
20.5 25.714285714285715
The system behaves differently when doing typical delta-based queries where a start date and end date
are specified using the comparison operators >=, >, <= and <. The comparison operators can be used
on the History and WideHistory tables. The comparison operators also apply regardless of how t he query
is executed (for example, four-part naming, OLE DB provider views, and so on).
Delta queries that use the comparison operators return all the valid changes to a set of tags over the
specified time span. Using deadbands and other filters may modify the set of valid changes.
If the start date is specified using >= (great er than or equal to), then a row is always returned for the
specified start date. If the start date/time coincides exactly with a valid value change, then the Quality is
normal (0). Otherwise, the value at the start date is returned, and the Quality value is 133 (becaus e the
length of time that the tag's value was at X is unknown).
Query 1
For this query, the start date will not correspond to a data change:
The start time (12:00:30) does not correspond with an actual change in value, and is therefore marked
with the initial quality of 133:
The first row returned is the first valid change after (but not including) the start time (12:00:30):
FROM History
WHERE TagName = 'SysTimeMin'
AND wwRetrievalMode = 'Delta'
AND DateTime > '2001-01-13 12:01:00'
AND DateTime < '2001-01-13 12:10:00'
The start time (12:01:00) corresponds exactly with an actual change in value, but it is excluded from the
result set because the operator used is greater than, not greater than or equal to.
The query does not capture an actual change in value; therefore, no rows are returned.
(0 row(s) affected)
Note that there is a valid change at exactly the end time of the query (12:10:00):
Note that there is a valid change at exactly the end time of the query (12:10:00), but it is excluded from
the result set.
(9 row(s) affected)
Cyclic queries with the wwCycleCount time domain extension return a set of evenly spac ed rows over the
specified time span. The result set will always return the number of rows specified by the cycle count
extension for each tag in the query. The resolution for these rows is calculated by dividing the time span
by the cycle count.
DateTime Value
2001-01-13 12:00:00.000 0
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
(60 row(s) affected)
The row that equates to the time which is designated using the < (or >) operator is not returned.
These queries use the remote table view.
Query 1
This query uses a cycle count of 60, resulting in a 1 second resolution for the dat a. The starting time is set
to >=.
DateTime Value
2001-01-13 12:00:00.000 0
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
(60 row(s) affected)
Query 2
This query also uses a cycle count of 60, resulting in a 1 second resolution for the data. The ending time
is set to <=.
DateTime Value
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
2001-01-13 12:01:00.000 0
(60 row(s) affected)
DateTime Value
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
2001-01-13 12:01:00.000 0
(60 row(s) affected)
DateTime Value
2001-01-13 12:00:00.000 0
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
2001-01-13 12:01:00.000 0
(61 row(s) affected)
Using One Equality Operator for Comparison with Cyclic Retrieval and
Resolution
If the start time is excluded (by using > instead of >=), then a gap of "resolution" is left at the beginning of
the result set. In this case, the first row returned will have the timestamp of the (start date + resolution). If
the end date uses "<" then the last row returned will be the last row defined by (start date + N*resolution)
which has a timestamp less than the end date.
The row that equates to the time that is designated using the < (or >) operator is not ret urned.
Query 1
This query uses a resolution of 1000, resulting in a 1 second resolution for the data.. The starting time is
set to >=.
DateTime Value
2001-01-13 12:00:00.000 0
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:55.000 55
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
(60 row(s) affected)
Query 2
This query also uses a row resolution of 1000, resulting in a 1 s econd res olution for the data. The starting
time is set to <=.
DateTime Value
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
2001-01-13 12:01:00.000 0
(60 row(s) affected)
DateTime Value
2001-01-13 12:00:01.000 1
2001-01-13 12:00:02.000 2
2001-01-13 12:00:03.000 3
2001-01-13 12:00:04.000 4
...
2001-01-13 12:00:56.000 56
2001-01-13 12:00:57.000 57
2001-01-13 12:00:58.000 58
2001-01-13 12:00:59.000 59
DateTime Value
2001-01-13 12:01:00.000 0
(60 row(s) affected)
You can return the amount of time before a tag's value changed to a subs equent value. This time is
returned using the wwResolution column.
This functionality works with the cyclic, delta, and full retrieval modes. The delt a and full mode behavior
of wwResolution does not apply to the AnalogSummary History and StateS ummaryHistory tables.
If the time change value is great er than 2,147,000,000 milliseconds (~25 days), then the value of
wwResolution column is -1.
Example 1: Cyclic Retrieval on page 158
Example 2: Delt a and Full Retrieval on page 159
Example 3: Querying the WideHistory Table on page 160
Example 4: Querying the History Table wit h the wwValueSelector Parameter on page 161
Example 5: Calc ulating Total Time Bet ween Value Changes on page 162
DateTime Value
2012-01-01 07:59:53 34.42384
2012-01-01 08:00:13 15.02637
2012-01-01 08:00:33 20.29732
2012-01-01 08:00:53 37.40273
2012-01-01 08:01:13 24.31662
For cyclic retrieval, cycles start at the start DateTime and occur at intervals specified by wwResolution in
the query. If you query for the data 2012 -01-01 08: 00:00 to 2012-01-01 08:01:00 with four cycles, the
wwResolution column in the results show the time in milliseconds until the next point.
DateTime Value
2012-01-01 07:59:53 34.42384
If you query for the data bet ween 2012 -01-01 08:00:00 to 2012-01-01 08:00: 10, the results are:
Value wwResolution
DateTime
2012-01-01 08:00:00 34.42384 NULL
When the last point in the result occurs before the query end time, the wwResolution column shows the
time until the end of the query when there is a next available point. If there are no more points, then the
wwResolution column shows NULL.
For example, the following is stored:
Value
DateTime
2012-01-01 07:59:53 34.42384
2012-01-01 08:00:13 15.02637
2012-01-01 08:00:33 20.29732
2012-01-01 08:00:53 37.40273
2012-01-01 08:01:13 24.31662
If you query for data from 2012-01-01 08:00:00 to 2012-01-01 08:05: 00, the results are:
Value wwResolution
DateTime
2012-01-01 08:00:00 34.42384 13000
2012-01-01 08:00:13 15.02637 20000
2012-01-01 08:00:33 20.29732 20000
Value wwResolution
DateTime
2012-01-01 08:00:53 37.40273 20000
2012-01-01 08:01:13 24.31662 NULL
If you query for data from 2012-01-01 08:00:00 to 2012-01-01 08:01: 00, the results are:
Value wwResolution
DateTime
2012-01-01 08:00:00 34.42384 13000
2012-01-01 08:00:13 15.02637 20000
2012-01-01 08:00:33 20.29732 20000
2012-01-01 08:00:53 37.40273 7000
If the last point happens to be end of the query, then the wwResolution value is zero, even when there
are no more points after the last point. For example, if you query for data from 2012-01-01 08:00:00 to
2012-01-01 08:01:13, the results are:
Value wwResolution
DateTime
2012-01-01 08:00:00 34.42384 13000
2012-01-01 08:00:13 15.02637 20000
2012-01-01 08:00:33 20.29732 20000
2012-01-01 08:00:53 37.40273 20000
2012-01-01 08:01:13 24.31662 0
The wwResolution column shows 1000 milliseconds because the smallest time change is for the
SysTimeSec tag, which is changing every second.
If you run the same query using the SysTimeHour tag instead of the SysTimeS ec tag, the results are:
The wwResolution column shows 60000 milliseconds becaus e the smallest time change is for the
SysTimeMin tag, which is changing every minute (every 60 seconds ). Because the query ended at the
time of the last value, a 0 is shown for wwResolution for the ending value.
The following query shows how to return the total time when both tags had a value of 0:
If you changed the ending WHERE clause to Total> 0, the returned time would be for when more than
one discrete tag was true.
The following queries show how to insert manual data int o a normal SQL Server table and then move it
into the History extension table.
First, insert the data into the SQL Server table. The following query inserts two minutes of existing data
for the SysTimeS ec tag into the ManualAnalogHistory table:
In general, an OPC quality has 16 significant bits. The lower 8 bits contain the quality as described in the
table, while the upper 8 bits hold server-specific information. To ensure correct results, it is important to
consider only the lower 8 bits in a query or join involving the OP CQualityMap table.
For example:
You cannot use variables in an OPENQUERY statement. Therefore, if you want to use variables in a
query on the wide table, you must first build up the OPENQUE RY statement "on the fly" as a string, and
then execute it.
Upon ret rieval, additional data points (labeled A and B) will be added to mark the end of the first block's
data and the beginning of the second block's data. Point C is a stored point generated by the Storage
subsystem. (Upon a restart, the first value from each IDAS will be offset from the start time by 2 seconds
and have a quality detail of 252.)
The following paragraphs explain this in more detail.
For delta retrieval, the data values in the first block are returned as stored. After the end of the block is
reached and all of the points have been ret rieved, an additional data point (A) will be inserted by retrieval
to mark the end of the data. The value for point A will be
Value 0 0
Quality Detail 0 0
If there is no value stored at the beginning of the next block, an initial data point (B) will be inserted by
retrieval and will have the snapshot initial value as stored. The quality and quality detail values are as
follows:
Quality 0 0
In the case of cyclic retrieval, a point is required for each specified time. If the time coincides with the data
gap, a NULL point for that time will be generated. The inserted points will have the values defined in the
following table.
Value 0 0
Quality Detail 0 0
If you are using time or value deadbands for delta retrieval across a data gap, the behavior is as follows:
For a value deadband, all NULLs will be returned and all values immediately after a NULL will be
returned. That is, the deadband is not applied to values separated by a NULL.
For a time deadband, null values are treated like any other value. Time deadbands are not affected
by NULLs.
Quality 0 0
For cyclic retrieval, NULL will be returned for data values that occur before the start of the history block.
Another non-valid start time is a start time that is later than the current time of the AVEVA Historian
computer. For delta retrieval, a single NULL value will be returned. For cyclic retrieval, a NULL will be
returned for each data value requested.
SysTimeSec AVG
29.5
Query 2
The following query uses the historian time-weighted average retrieval mode to return the average for
the same time period. Because the cycle count is set to 2, a first row is returned for the "phantom"cycle
leading up to the query start time. The StartDateTime column shows the time stamp at the start of the
data sampling, which is the start time of the phantom cycle. The second row ret urned reflects is the
actual data that you expect. The time stamp for the data value is 2009 -11-15 06: 31:00 because the
default time stamping rule is set so that the ending time stamp for the cycle is returned. For more
information about the phantom cycle, see About Phantom Cycles on page 93.
SELECT
CONVERT(BIT, CAST(Value AS INT) & 1) As 'Bit0',
CONVERT(BIT, CAST(Value AS INT) & 2) As 'Bit1',
CONVERT(BIT, CAST(Value AS INT) & 4) As 'Bit2',
CONVERT(BIT, CAST(Value AS INT) & 8) As 'Bit3',
CONVERT(BIT, CAST(Value AS INT) & 16) As 'Bit4',
CONVERT(BIT, CAST(Value AS INT) & 32) As 'Bit5',
CONVERT(BIT, CAST(Value AS INT) & 64) As 'Bit6',
CONVERT(BIT, CAST(Value AS INT) & 128) As 'Bit7'
FROM dbo.History WHERE TagName = 'SysTimeMin'
1 0 1 1 0 0 0 0
0 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0
C HAPTER 4
SQL Queries for Alarms and Events
Note: The alarm and event history functionality described in this chapter captures detailed histories
from Application Server. This functionality should not be confused with the Classic E vent subsystem
allows for some basic events tracking and is based on historical data.
AVEVA Historian captures proc ess data about your plant. In addition to real -time and historical data, this
includes information about events.
E vents are like other process data – for example, temperature – because their values can change over
time. Events differ from other process data in these ways:
E vents usually change more slowly.
E vents usually are more complex than simply a value, time, and quality.
E vent data ans wers questions like "When did this setpoint change and who changed it?" The event
record could include the name of the operator, the workstation from where the change was made, any
comment about the change, the name of the person who verified the change, and other related details.
Alarms are a specific kind of event. They represent state changes and have an associated lifecycle. This
lifecycle includes these states (usually in this order):
Set – For example, when a temperature goes too high.
Acknowledged – That is, when an operator rec ognizes it as an alarm and, ideally, addresses it.
Clear – For example, when the temperature returns to normal.
Alarms may also have other states, but these are the key ones.
You can query the E vents view, which references the History table, to track and analyze alarms and
other events. Because Events is actually an extension table (like History), its data is stored in blocks, not
in SQL Server tables.
Note: The E vents view does not expose all application-specific columns that may be stored by Historian.
(Such columns are queryable from the RES T/OData int erface.) Also, it is not unusual for E vents columns
to contain many NULL values.
For more information about the E vents view, see E vents in the AVEVA Historian Database Reference.
SELECT *
FROM Events
WHERE EventTime between '2015-10-25 0:00' and '2015-10-26 0:00'
FROM @AlarmRaise
GROUP BY CAST(EventTime as date),
DATEPART(hour,EventTime),
SourceObject,
SourceConditionVariable
ORDER BY ForDate ASC,OnHour,[Alarm Attribute]
2017-11-10 12 10 AlarmHeartBeatAlarmHeartBeat.AlmHeartBeat.Hi
2017-11-10 12 2 Reactor_31Reactor_31.ReactLevel. Hi
2017-11-10 12 2 Reactor_31Reactor_31.ReactLevel. Lo
2017-11-10 12 2 Reactor_31Reactor_31.React Temp.Hi
2017-11-10 12 1 StorageTank_31StorageTank_31.ProdLevel.Lo
2017-11-10 12 6 VectorTagsVectorTags.VectorX. Hi
2017-11-10 12 3 VectorTagsVectorTags.VectorX. HiHi
2017-11-10 12 6 VectorTagsVectorTags.VectorX. Lo
2017-11-10 12 3 VectorTagsVectorTags.VectorX. LoLo
2017-11-10 12 2 VectorTagsVectorTags.VectorZ.Hi
Area_001 6
UserDefined_001 6
-- ack time per severity per hour for high, medium and low
AlarmDuration nvarchar(20)
)
INSERT @AlarmClear
SELECT EventTime,Alarm_ID,Alarm_DurationMs
FROM Events
WHERE EventTime > @StartTime and EventTime < @EndTime and
Type='Alarm.Clear'
--======================--
SELECT 'Alarm Life - '+ s.ID
,CASE
WHEN a.EventTime > c.EventTime THEN 'Cleared Before
Ack'
WHEN a.EventTime < c.EventTime THEN 'Acked Before
Clear'
ELSE '-' END as Comment
,s.EventTime as AlarmRaised
,a.EventTime as AlarmAcked
,c.EventTime as AlarmClear
,a.UnAckDuration as UnAckDuration
,c.AlarmDuration as AlarmDuration
UnAck Alarm
(No column Duratio Durati
name) Comment AlarmRaised AlarmAcked AlarmClear n on
Alarm Life -
B0718EAE-13
01-1D00-46D6
-061A5265589 Cleared 2017-12-12 2017-12-12 2017-12-12
F Before Ack 12:00: 01.2540000 12:00: 56.5170000 12:00: 13.1430000 55263 11889
Alarm Life -
5FE1D46F-C6
D7-D7C6-DB2 Acked
4-A832B0361 Before 2017-12-12 2017-12-12 2017-12-12
562 Clear 12:00: 40.1220000 12:00: 56.5150000 12:01: 00.1220000 16393 20000
Alarm Life -
39DB F54B -B4
ED-6D35-C1D
F-19EE 53D62 Cleared 2017-12-12 2017-12-12 2017-12-12
211 Before Ack 12:00: 48.1290000 12:00: 56.9600000 12:00: 52.1240000 8831 3995
Alarm Life -
973B 8CEA-D
BDA-7B 4B-18 Acked
3A-E423B109 Before 2017-12-12 2017-12-12 2017-12-12
8C91 Clear 12:00: 57.6870000 12:00: 58.7880000 12:01: 03.6230000 1101 5936
Alarm Life -
B926FB 71-B 6
DE-4916-C23
C-CC85D5B 0 Cleared 2017-12-12 2017-12-12 2017-12-12
1BDE Before Ack 12:01: 45.7120000 12:01: 57.0140000 12:01: 53.2410000 11302 7529
Alarm Life -
A52B65BE -27
F2-CC6A-936
9-EDFD3E6D Cleared 2017-12-12 2017-12-12 2017-12-12
7514 Before Ack 12:01: 47.1270000 12:01: 57.0160000 12:01: 52.7340000 9889 5607
Alarm Life -
AFE96385-10
B4-F695-9302
-320F02FA46 Cleared 2017-12-12 2017-12-12 2017-12-12
A1 Before Ack 12:01: 51.1570000 12:01: 57.0180000 12:01: 53.6230000 5861 2466
C HAPTER 5
Browser-Friendly Data Retrieval
Historian Data REST API
With Historian Data RES T API, you can upload data to and retrieve it from your Insight solution.
You can use thes e types of requests with Historian Data
RES T API:
Upload requests us e the POST met hod to an upload
endpoint URL.
Upload requests send data or metadata to a specific
data source within your Insight solution.
See Dat a upload for details about upload requests.
Retrieval requests use the GE T met hod and a
different endpoint URL for retrieval from your Insight
solution.
See Dat a retrieval (see " Data retrieval" on page 183)
for two methods to retrieve dat a.
You can submit requests to the Historian Data RES T AP I using a web browser or a client -side
applications such as these:
Microsoft Excel (2013, 2016, or Office 365)
Business Intelligence (B I) systems, such as Tableau and Microsoft Power BI
Supported OData features
ODat a is an industry standard for querying and updating data from a variety of sources. The
implementation of ODat a for the Historian Data RES T API includes support for:
JSON and atom formats.
ODat a versions 3 and 4.
Pagination. That is, if your request returns more than 5000 results, they will be returned in pages of
up to 5000 records. Each page will include a link to retrieve the next page of rec ords.
A subset of the OData system query options.
For more information, see OData.org JS ON Verbose Format specification.
Recommendation: For best results, when you want to view the dat a returned by the Historian Data
RES T API, use the JS ONView extension for the Chrome browser.
Supported versions
Insight supports versions 1 and 2 of the Historian Data RES T AP I.
Version 2
This is the current and recommended version of the Historian Data RES T API.
Version 2 of this REST APis based on version 1 and includes furt her enhancements. Version 2 includes
these differences from version 1:
The TagFilter parameter is support ed as a part of a GE T or POS T query used with
ProcessValues, AnalogSummary, and StateSummary resources.
The datetimeoffset parameter is not supported as part of the DateTime syntax.
While Raw and ProcessValue entities use DateTime, summary entities use StartDateTime and
EndDateTime.
For most version 2 queries, single quotes are not used for DateTime. For example:
https://online.wonderware.com/apis/Historian/v2/ProcessValues
?$filter=DateTime+gt+2017-07-13T00:00:00
However, when querying events, single quotes are required for DateTime. For example:
https://online.wonderware.com/apis/Historian/v2/Events
?$filter=EventTime+gt+'2017-07-13T00:00:00'
By contrast, version 1 queries do use single quotes for DateTime. For example:
https://online.wonderware.com/apis/Historian/v1/ProcessValues
?$filter=DateTime+gt+datetimeoffset'2017-07-13T00:00:00'
TagProperty (see "TagProperties" on page 212) and Events (see "Events" on page 200) entity types
are now open type. That is, dynamic properties can be added to the res pons e at runtime. This can be
verified using $metadata endpoint URL:
https://online.wonderware.com/s/<solution_id>/apis/historian/v2/$metadata
where there will be additional attribute, OpenType="true", under <EntityType> section.
The Tags resource (see "Tags" on page 206) returns all the properties (fixed and extended) for a tag.
A tag's extended properties will be added to the response only if they exist. (The extended property
name will not be listed for tags that do not have a given extended property.)
The combined Summary resource (see "Summary (v1 only)" on page 220) is not supported in
version 2. Use the individual AnalogSummary (see "AnalogSummary" on page 191) and
StateSummary (see "StateSummary" on page 197) resources instead to retrieve the summary of a
tag.
Insight returns a list of resources and endpoints in JSON format instead of the previously used XML
when you specify the default endpoint URL for your solution (where < solution_id> is the identifier for
your Insight solution:
https://online.wonderware.com/s/<solution_id>/apis/historian/v2
Version 2 adds support for the OData contains function for applicable resources and properties.
Version 1
This is the original version of Historian Data RES T API based on the OData v4 specification.
Version 1 us es the DateTime format used in this example:
https://online.wonderware.com/s/ik97r5/apis/Historian/v1
/AnalogSummary?$filter=FQN+eq+'Baytown.tank_level'
+and+StartDateTime+ge+datetimeoffset'2016-05-14T00:00:00.000-07:00'
+and+EndDateTime+le+datetimeoffset'2016-05-16T00:00:00.000-07:00'
Data retrieval
The Historian Data REST AP I allows you to retrieve data from your Insight solution.
Retrieval requests use a GE T method and a retrieval
endpoint URL. The retrieval endpoint URL differs depending
on whether you are using token authentication (with a
retrieval token) or basic authentication, wit h no token.
GET method with basic authentication
Requests to retrieve data via basic authentication require
no ret rieval token. Rather, these requests must use the
endpoint URL specified by the Integration Settings page.
Get details here.
GET method with token authentication
You can use retrieval token to access your Insight data
using token authentication. Get det ails here.
https://online.wonderware.com/s/<solution_ID>/apis/historian/<api_version
>/<resource>?<query_parameters>
With token authentication, use syntax to form your ret rieval requests:
https://online.wonderware.com/apis/historian/<api_version>/<resource>?<qu
ery_parameters>
https://online.wonderware.com/apis/historian/v2/
AnalogSummary?$filter=FQN+eq+'Baytown.tank_level'
Or, RES T parameters; for example " TagFilter", as in this syntax:
https://online.wonderware.com/apis/historian/v2/
AnalogSummary?TagFilter=FQN eq 'Baytown.tank_level’
For example, this retrieval request gets analog summary dat a via an endpoint URL using basic
authentication:
https://online.wonderware.com/s/ik97r5/apis/historian/v2/AnalogSummary
?$filter=FQN+eq+'Depot.Train09'+and+StartDateTime+ge+2017-06-09T09:00:00-
07:00+and
+EndDateTime+ge+2017-06-09T10:00:00-07:00&Resolution=3600000
Resolution specifies the granularity of data returned for Raw, Proc essValues, and Summary
entities.
Using TagFilter
You can use the TagFilter parameter as a part of a GE T or POS T query with ProcessValues,
AnalogSummary, and StateSummary resources. See examples. (see "Retrieve data using PowerBI" on
page 236)
It allows a query string using ODat a filter query notation.
TagFilter can include:
Up to 20 A ND claus es
Up to 20 OR clauses
Up to 2 UDF clauses
You cannot mix AND and OR in the same query.
Operators should be lowerc ase.
Valid Format:
Historian/v2/ProcessValues?TagFilter=startswith(Source,'MVDS') and TagType
eq 'string'
Invalid Format:
Historian/v2/ProcessValues?TagFilter=startswith(Source,'MVDS') And TagType
eq 'string'
Most searches are case-ins ensitive. However, search by these attributes is case-sensitive:
InterpolationTy pe
MessageOn
MessageOff
These are the supported (and not supported) features for TagFilter:
V2 controllers V1 controller
Use with ProcessValues, AnalogSummary and Toupper and tolower functions
StateSummary
Nested query with grouping precedence operator;
GET and POS T queries that is: ‘()’
StartsWith, EndsWith Query with mixed operator like "and, or"
SkipToken These attributes support only "eq" and not "startswith
or endswith"
Nested query with same operator type ("and" or
"or"). Examples: o EngUnitMax
o EngUnitMin
Historian/v2/ProcessValues?
TagFilter= o InterpolationTy pe
startswith(Source,'MVDS') and TagType
eq 'string' and EngUnit eq ‘None’ o MessageOff
o MessageOn
Historian/v2/ProcessValues?
TagFilter= o Any TagExtendedProperty that is not a string
startswith(Source,'MVDS') or TagType (booleans, integers, doubles, guids)
eq 'string' or EngUnit eq ‘None’ Geospatial primitives, such as Geoloc ation,
Geography, Geometry are not fully supported by
TagFilter .
Token Description
$filter Specifies an expression or function that must evaluat e to true for a record to be returned in the
collection.
All typical OData functions are supported for the $filter clause.
The $filter ex pression supports references to properties and literals. Literal values include:
Strings enclosed in single quotes
Numbers and Boolean values (true or false)
Filtering for process value and summary data is case-sensitive.
However, while event property names are case-s ensitive, filtering is case-insensitive. For
example, if you filter property values based on a value of "true," values such as "TRUE," "True,"
and "true" could be returned. The case ret urned in the query res ults reflects the case of the stored
value.
$skip Specifies the number of records to skip from the beginning of the res ult set.
Token Description
$skiptoken Used to get the next record set that satisfies the query conditions. You do not need to include this
token in the query, but you will see it upon query execution.
$top Specifies the maximum number of records to return. This subset is formed by selecting only the
first N items of the set, where N is a positive integer specified by this query option.
These logical operat ors are supported for the query options:
Operator Description
eq Equal
ne Not equal
gt Greater than
lt Less than
or Logical or
In the filter expression, you can have only a single time clause combined with a single filter clause using
the "and" operator. The filter clause itself can be complex, using any of the supported logical operators.
Use parentheses ( ) to create precedence groups within an expression in filter claus e.
Note: Use "%20" to indicate a space. Use "%27" to indicate a single quote.
If you are using the JSONView viewer in the Chrome browser, you can use a plus sign (+) to indicate a
space to make the URI string more readable.
If the expression includes multiple values for the criteria, you must specify each criteria separately using
the "or" operat or. For example:
...
((Priority+eq+100+or+Priority+eq+200+or+Priority+eq+500+or+Priority+eq+70
0)+and+(filter …))
Retrieval resources
The Historian Data REST AP I exposes various resources through an endpoint URL that is specific to
your Insight solution.
This API includes the following res ourc es for retrieving data:
Process Data and Tag Property Resource s Resource s for Version 1 Only
Events Re source s
Note: All property names are case-sensitive. E vent storage preserves the case that you provide for any
property value. For example, a property value of " TRUE" is different than " True" and "true."
ProcessValues
Description Retrieves a set of process value records (where each record includes value +
time + quality, or VTQ) for the specified tags.
/ProcessValues
URL
GET
Method
https://online.wonderware.com/apis/historian/v2/Process
Values
?TagFilter=endswith(FQN, 'level').
See more TagFilter examples. (see "Retrieve data using PowerBI" on page
236)
Scenario 2
This query returns proc ess values for a specific tag identified by its fully
qualified name (datasource.tagname). Using a"$filt er" clause, it specifies a
tag named tank_level within the Baytown data source. The result is a list of
values for the tank_level tag.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/ProcessValues
?$filter=FQN+eq+'Baytown.tank_level'
Scenario 3
This query includes a start date time, end dat e time, and other query
parameters.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/ProcessValues
?$filter=FQN+eq+'Baytown.tank_level'and DateTime ge
2014-07-04T23:57:29Z
and DateTime le
2014-07-05T00:02:29Z&RetrievalMode=BestFit&Resolution=6
500
{
Sample Output "odata.metadata":
"https://online.wonderware.com/s/ik97r5/apis/historian/
v2/
$metadata#ProcessValues",
"value": [
{
"FQN": "20140805AK.TestSkipToken_0",
"DateTime": "2014-08-06T17:25:19.216486Z",
"OpcQuality": 192,
"Value": 39816,
"Text": "39816"
},
{
"FQN": "20140805AK.TestSkipToken_0",
"DateTime": "2014-08-06T17:25:20.196Z",
"OpcQuality": 192,
"Value": 39817,
"Text": "39817"
}
],
}
AnalogSummary
Description Retrieves analog statistics for the specified tags.
/AnalogSummary
URL
GET
Method
PercentGood=[Double]
The ratio of the number of rows that have "good" quality to the total
number of rows in the retrieval cycle, expressed as a percentage in the
range 0 to 100.
First=[Double]
If at least one non-NULL point exists for the tag in question within the
retrieval cycle, then the value returned is the first point stored with a time
stamp within the retrieval cycle. If no points exist within the retrieval
cycle, then the value returned is the current value at the cycle start time.
If no non-NULL points can be found, then NULL is returned.
FirstDateTime=[DateTimeOffset]
Timestamp associated with first value. This might be earlier than
StartDateTime if this is the initial value for the retrieval cycle.
Last=[ Double]
If at least one non-NULL point exists for the tag in question within the
retrieval cycle, then the value returned is the last point stored with a time
stamp within the retrieval cycle. If no points exist within the retrieval
cycle, then the value returned is the current value at the cycle start time.
If no non-NULL points can be found, then NULL is returned.
LastDateTime=[DateTimeOffset]
Timestamp associated with last value. This might be earlier than
StartDateTime if this is the initial value for the retrieval cycle.
Minimum=[Double]
If at least one non-NULL point exists for the tag in question within the
retrieval cycle, then the value returned is the minimum point stored with a
time stamp within the retrieval cycle. If no points exist within the retrieval
cycle, then the value returned is the current value at the cycle start time.
If no non-NULL points can be found, then NULL is returned.
MinDateTime=[DateTimeOffset]
Timestamp associated with Min value. NULL if Min is NULL.
Maximum=[Double]
If at least one non-NULL point exists for the tag in question within the
retrieval cycle, then the value returned is the maximum point stored with
a time stamp within the retrieval cycle. If no points exist within the
retrieval cycle, then the value returned is the current value at the cycle
start time.
If no non-NULL points can be found, then NULL is returned.
MaxDateTime=[DateTimeOffset]
Timestamp associated with Max value. NULL if Max is NULL.
Average=[Double]
Time weighted average value of retrieval cycle. This is calculated by
using the individual summary averages. The c alculation is "Sum(average
* delta t) / Total time of average in all cycles" - delta t is prorated for any
partially contained storage cycles For analog tags, the calculation is
"Sum(value * delta t) / Total time. (This is like the values returned by an
A verage query against the History table for a cycle of the same lengt h,
where the History row DateTime is the same as the EndDateTime here.)
StdDev=[Double]
Time weighted standard deviation value of the retrieval cycle. The value
is calculated using time weight ed sums (Integrals) and time weighted
sums of squares (IntegralOfSquares) values, prorated for any partially
contained storage cycles.
For analog tags, similar StdDev values are produced for eac h cycle.
Integral=[Double]
Area under value curve of retrieval cycle. The calculation is "Sum(value *
delta t) / Tot al time of int egral in all cycles" - delta t is prorated for any
partially contained storage cycles For analog tags, the calculation is
"Sum(value * delta t) / Total time. (This is like the values returned by an
Integral query against the History table for a cycle of the same length,
where the History row DateTime is the same as the EndDateTime here.)
For analog tags, similar Int egral values are produced for each cycle.
Count=[Double]
Number of values in a particular cycle.
https://online.wonderware.com/apis/historian/v2/AnalogS
ummary?TagFilter=
endswith(FQN, 'level').
See more TagFilter examples. (see "Retrieve data using PowerBI" on page
236)
Scenario 2
This query produces a list of values wit h analog summary for the tank_level
tag.
Notice that this example us es a fully qualified name ("Baytown.t ank_level"),
which is a combination of a data sourc e name ("Baytown") and a tagname
("tank_level").
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/AnalogSummary
?$filter=FQN+eq+'Baytown.tank_level'
Because this query specifies no start or end time and no resolution, these
defaults are used for the ret urned results:
EndTime defaults to Dat eTime. UtcNow
StartTime defaults to one hour before EndTime
Resolution defaults toTimespan
Count defaults to1 (number of returned rows)
Scenario 3
This query produces a list of tag values with analog summary data. The
"$filter" clause narrows the results further by specifying these parameters:
Fully qualified name of the tag (FQN+eq+'B aytown.tank_level')
Start and end times
Result set returned at 1 hour intervals (Resolution=3600000). There are
3.6 million milliseconds in an hour.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/AnalogSummary
?$filter=FQN+eq+'Baytown.tank_level'+and+StartDateTime+
ge+2017-05-14T00:00:00.000Z
+and+EndDateTime+le+2017-05-16T00:00:00.000Z&Resolution
=3600000
Scenario 4
This query specifies only Start Time and Resolution (600000 ms, or 10
minutes), but no EndTime.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/AnalogSummary
?$filter=FQN+eq+'Baytown.tank_level'
and StartDateTime ge
2017-06-29T00:00:00Z&Resolution=600000
In this case, Insight assumes:
EndTime defaults to Dat eTime. UtcNow
The number of rows returned (Count) depends on the Start Time and
EndTime.
Scenario 5
This query specifies only EndTime, but no Start Time or Res olution.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/AnalogSummary
?$filter=FQN+eq+'Baytown.tank_level'and EndDateTime le
2017-06-29T00:00:00Z'
In this case, Insight assumes:
StartTime defaults to one hour before EndTime
Resolution defaults toTimespan
Count defaults to1 (number of returned rows)
Scenario 6
This query specifies uses SliceBy.
https://online.wonderware.com/apis/Historian/v2/AnalogS
ummary?$
filter=FQN+eq+'Baytown.R21.Level'+and+StartDateTime+ge+
2019-03-05T00:00:00.000Z+
and+EndDateTime+le+2019-03-05T12:00:00.000Z&SliceBy=Bay
town.R21.Batch
In this case, Insight calculat es an analog summary for the
Baytown..R21.Level tag and batches the results per value for the
Baytown. R21.Batch tag.
StateSummary
Description Retrieves state summary values for the specified tags.
/StateSummary
URL
GET
Method
https://online.wonderware.com/apis/historian/v2/StateSu
mmary?TagFilter=
endswith(FQN, 'pump_03').
See more TagFilter examples. (see "Retrieve data using PowerBI" on page
236)
Scenario 2
This query specifies no start or end time and no resolution.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/StateSummary
?$filter=FQN eq 'Baytown.pump_03'
In this case, these defaults are used for the returned results:
EndTime defaults to Dat eTime. UtcNow
StartTime defaults to one hour before EndTime
Resolution defaults toTimespan
Count defaults to1 (number of returned rows)
Scenario 3
This query specifies only Start Time and Resolution (600000ms, or 10
minutes), but no EndTime.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/StateSummary
?$filter=FQN eq 'Baytown.pump_03' and StartDateTime ge
2017-06-29T00:00:00Z&Resolution=600000
In this case, Insight assumes:
EndTime defaults to Dat eTime. UtcNow
The number of rows returned (Count) depends on the Start Time and
EndTime.
Scenario 4
This query specifies only EndTime, but no Start Time or Res olution.
https://online.wonderware.com/s/ik97r5/apis/historian/v
2/StateSummary
?$filter=FQN eq 'Baytown.pump_03' and EndDateTime le
2017-06-29T00:00:00Z
In this case, Insight assumes:
StartTime defaults to one hour before EndTime
Resolution defaults toTimespan
Count defaults to1 (number of returned rows)
Events
Description Retrieves information about events and alarms.
Note: All property names are case-sensitive. E vent storage preserves the case
that you provide for any property value. For example, a property value of "TRUE"
is different than " True" and "true."
/Events
URL
GET
Method
Optional ID=[GUID]
Parameters Globally unique identifier for the event.
EventTime=[DateTime]
UTC timestamp indicating when the event occurred.
Type=[String]
Main categorization of the event. Examples of valid values:
- Alarm.Acknowledge - Application.Write
- Alarm.Clear - User.Write
- Alarm.Set - User.Write.Secured
- Alarm.Write - User.Write.Verified
Priority=[Int32]
Value indicating the import ance of the event. Values range from 1 to 999,
with lower numbers indicating higher importance.
Namespace =[String]
The namespace for this event tag.
Severity=[Int32]
Categoriz ation of the urgency of the event:
1 - Critical
2 - Major
3 - Minor
4 - Informational
EventTimeUTCOffsetMins=[Int 32]
For local time, the offset in minutes from UTC time.
ReceivedTime=[DateTime]
UTC timestamp indicating when the event was received by the Historian
server.
IsAlarm=[Bool]
"true" or "false" indicating whether this event is an alarm.
Comment=[String]
A comment providing more information about the event.
Optional InTouchType=[String]
Parameters InTouch Type value. Examples include:
- ALM
- RTN
- ACK
- SYS
ValueString=[String]
The current value string.
PreviousValueString=[String]
The previous value string.
https://online.wonderware.com/s/ik97r5/apis/Historian/v2/E
Sample Queries vents
?$filter=EventTime+gt+'2017-07-13T00:00:00'
https://online.wonderware.com/s/ik97r5/apis/Historian/v2/E
vents
?$filter=type+eq+'Alarm.Clear'
{
Sample Output @odata.context:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v2/
Events
/$metadata#Events",
value: [
{
id: "ee9b042c-181e-4872-b4e8-cb9575c1f4f9",
eventtime: "2017-07-13T00:00:01.047Z",
type: "Alarm.Clear",
receivedtime: "2017-07-13T00:00:01.2553666Z",
source_name: "AaEvents",
namespace: "AaEvents",
alarm_acknowledged: false,
alarm_class: "VALUE",
alarm_condition: "Limit.LoLo",
alarm_durationms: 5006,
alarm_id: "f1e21e43-352e-d3db-7552-6e77f193d02d",
alarm_inalarm: false,
alarm_isshelved: false,
alarm_issilenced: false,
alarm_limitstring: "10.0",
alarm_originationtime: "2017-07-12T23:59:56.041Z",
alarm_state: "UNACK_RTN",
alarm_tagtype: "S",
alarm_type: "LoLo",
comment: "Severity 1",
eventtimeutcoffsetmins: -420,
intouchtype: "LoLo",
isalarm: true,
priority: 1,
provider_applicationname: "AlarmsandEvents",
provider_nodename: "INSIGHTCHARTAPP",
provider_system: "Application Server",
provider_systemversion: "4966.1210.14578.2",
severity: 1,
source_area: "Plant_Area",
source_conditionvariable:
"Drum_Conveyor.HorizontalMovement.LoLo",
source_hierarchicalarea:
"Enterprise.Site.Plant.Plant_Area",
source_hierarchicalobject: "Drum_Conveyor",
source_object: "Drum_Conveyor",
source_processvariable: "Drum_Conveyor.HorizontalMovement",
valuestring: "30.0"
},
Tags
Description Using the GE T verb, ret rieves tag metadata. For version 2, this also includes
tag extended properties.
Using the POS Tverb, manages multiple tags at once.
Using the DELE TE verb, deletes a specified tag.
/Tags
URL
GET
Methods POST
DELETE
Required Parameters FQN=[string ]
The fully qualified name for the tag. A fully qualified name uses the format:
datasource.tagname.
Optional Parameters Source=[string ]
The data source.
Description=[string ]
The description of the tag.
EngUnit=[string]
The engineering units used for the tag's rec orded values.
EngUnitMax=[Double]
The maximum value of the tag, measured in engineering units.
EngUnitMin=[Double]
The minimum value of the tag, measured in engineering units.
The minimum value of the tag, measured in engineering units.
InterpolationType=[string]
The interpolation type for retrieval. 0 = Stair-stepped interpolation; 1 =
Linear interpolation (if applicable, based on the tag type); 254 = System
default interpolation mode. The system default interpolation type is to use
the system default for the analog type, either integer or real. The system
default interpolation type for an analog type is determined by the s etting of
the Int erpolationTypeInt eger and InterpolationTypeReal system
parameters. This setting impacts Interpolat ed, A verage, and Integral
retrieval modes.
IntegralDivisor=[ Double]
The factor to be applied when integrating a rat e with the units
[EngUnits/ TimeUnit] to a quantity with units [EngUnits]. This factor is
called the integral divisor.
The default value of 1 assumes a time unit of seconds and ensures that a
rate of [Unit/second] is correctly integrated to [Unit].
For a time unit of minut es, set the integral divisor value to 60; for a unit of
hours, set the integral divis or value to 3600. The integral divisor is applied
similarly to rates or quantities that are not expressed in terms of a time
unit. For example, to convert watts to watt-hours, the integral divisor is
1/3600. To convert watts to kilowatt-hours, the integral divisor is
1/3600000. Internal use only.
Get tags
Sample Query Scenario 1
This query lists tag metadata for all tags in all data sources
for your Insight solution.
https://online.wonderware.com/s/ik97r5/apis/historian/v2/
Tags
Scenario 2
This query lists metadata for tags in a particular data source. The data source
in this example is named Baytown.
https://online.wonderware.com/s/ik97r5/apis/historian/v2/
Tags?$filter=Source+eq+'Baytown'
{
Sample Output @odata.context:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/$metadata#Tags",
value: [
{
FQN: "14th aug app.Auto",
Source: "14th aug app",
Description: "Automatic mode",
EngUnit: "",
EngUnitMax: 0,
EngUnitMin: 0,
InterpolationType: "None",
MessageOff: "Manu",
MessageOn: "Auto",
TagName: "Auto",
TagType: "Discrete",
Alias: "nareshtag-discrete",
Location: "/Application Tag 2",
Raw@odata.navigationLink:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/Tags('14th%252baug%252bapp.Auto')/Raw",
Minutely@odata.navigationLink:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/Tags('14th%252baug%252bapp.Auto')/Minutely",
Hourly@odata.navigationLink:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/Tags('14th%252baug%252bapp.Auto')/Hourly",
Daily@odata.navigationLink:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/Tags('14th%252baug%252bapp.Auto')/Daily"
}
],
@odata.nextLink:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/Tags
?$skiptoken=koen66nr4nGCReC02FqdxO4Y62C7zBVsv3uf7mO8XMQqx
Zveqw8+v2/bVCsFdevT"
}
Delete a tag
Sample Query This query deletes a tag named Weather.Brisbane. Cloudiness.
DELETE /Historian/v2/Tags('Weather.Brisbane.Cloudiness')
HTTP/1.1
Host: nchdevruntime.cloudapp.net:8080
Content-Type: application/json
{
"delete":
{
"FQN":["datasourcename.tagname"]
}
}
"FQN":['Weather.Brisbane.Cloudiness','Weather.Auck
land.Cloudiness'],
"select":"FQN,TagName"
}
}
Note: Historian Data RES T API extended properties map to the AVEVA
Historian SDK tag extended properties API.
{
"properties":
[
{
"FQN": "18Jul_kc.test1",
"PropertyName": "Alias",
"Text": "SysTimeSec",
"Type": "String",
"Searchable":false
}
}
{
"value":
[
{
"FQN": "System.Tag1",
"$StatusCode": 200
},
{
"FQN": "System.Tag2",
"$StatusCode":500,
"$ErrorMessage":"Alias property contains illegal
characters"
}
]
}
TagProperties
Description Lists all properties used in the system. Tag properties include bot h base and
extended properties of a tag.
Examples of TagProperties are DataSourceName and Unit.
/TagProperties
URL
GET
Method
https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/TagProperties
{
Sample Output @odata.context:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v
2/$metadata#TagProperties",
value: [
{
Name: "DataSourceName",
Type: "String",
ReadOnly: true
},
{
Name: "Namespace",
Type: "String",
ReadOnly: true
},
{
Name: "TagName",
Type: "String",
ReadOnly: true
},
{
Name: "FullyQualifiedName",
Type: "String",
ReadOnly: true
},
...
TagPropertyValues
Description Retrieves values for one or more tag properties. Tag properties include base
and extended properties of Tag. Examples of TagProperties are
DataSourceName and Unit.
/TagpropertyValues
URL
GET
Method
https://online.wonderware.com/s/ik97r5/apis/Historian/v2
/TagPropertyValues
{
Sample Output
@odata.context:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v
2
/$metadata#TagPropertyValues",
value: [
{
Name: "Source",
Value: "Meter",
Tags@odata.navigationLink:
"https://online.wonderware.com/s/ik97r5/apis
/Historian/v2/TagPropertyValues(Name='Source',Value='Met
er')
/Tags"
},
{
Name: "Source",
Value: "Weather",
Tags@odata.navigationLink:
"https://online.wonderware.com/s/ik97r5/apis
/Historian/v2/TagPropertyValues(Name='Source',Value='Wea
ther')
/Tags"
}
]
}
TagGroups
Description Retrieves information about data sources. Each data source cont ains a group
of tags.
/TagGroups
URL
GET
Method
Scope=[string]
Used for tag-level security, this defines a location within the data source.
Tags
Identifies related Tags.
Groups
Identifies related TagGroups.
Sample Query This query lists the data sources (labeled " TagGroups" in this API) for your
Insight solution identified by solution ID. In this example, the solution ID used
is "ik97r5".
https://online.wonderware.com/s/ik97r5/apis/historian/v2
/TagGroups
{
Sample Output @odata.context:
"https://online.wonderware.com/s/ik97r5/apis/Historian/v
2
/$metadata#TagPropertyValues",
value: [
{
Name: "Source",
Value: "Meter",
Tags@odata.navigationLink:
"https://online.wonderware.com/s/ik97r5/apis
/Historian/v2/TagPropertyValues(Name='Source',Value='Met
er')
/Tags"
},
{
GroupID: "1cd29ff2-f7f3-428b-a593-55c917136a39",
GroupName: "Weather",
Type: "1000000",
ParentID: "0",
Scope: "Public",
Tags@odata.navigationLink:
"https://online.wonderware.com
/s/ik97r5/apis/Historian/v2/TagGroups
('1cd29ff2-f7f3-428b-a593-55c917136a39')/Tags",
Groups@odata.navigationLink:
"https://online.wonderware.com
/s/ik97r5/apis/Historian/v2/TagGroups
('1cd29ff2-f7f3-428b-a593-55c917136a39')/Groups"
}
]
}
TagSuggest
Description Retrieves content or tags based on search criteria from AVEVA Insight. It
returns the searc h results based on tag name, content name, keywords,
description, and so on. It also returns the summary of the search result -- for
example, total matching search results for the given search text.
You can use the these query options:
q -- (query) Limits the searc h to only specified fields instead of searching
all fields.
Type -- Limits the search to only a certain type of data (Tag or
SavedContent).
/TagSuggest
URL
GET
Method
Tags
Identifies related Tags.
ExpandSuggest
https://online.wonderware.com/s/ik97r5/apis/historian/v2
/TagSuggest
Scenario 2
This query uses the "q" query option to limit the search to only the "location"
field.
https://online.wonderware.com/s/ik97r5/apis/historian/v2
/TagSuggest
?q=&searchfields=location
Scenario 3
This query uses the "Type" option to limit the searc h to only a certain type of
data (Tag or SavedContent).
https://online.wonderware.com/s/ik97r5/apis/historian/v2
/TagSuggest?q=d&Type=Tag
TagSearch
Description Provides tagname results based on provided search parameters.
The data returned by this entity is dependent on the historian’s
implementation of search functionality. Some historians will return empty
result sets.
It finds all the matching results for a given query string. It is basically used to
filter the results based on the suggestion results. It searches for the matching
record only on the fields provided in the key name as part of the query
parameter. The results contain basic tag metadata information; such as FQN,
tagname, source, and search ranking.
You can use thes e query options:
q - Specifies the query string (for example, the value typed by the user into
the search box).
kn - Specifies the key name (field name) to which the search will be
applied.
kv - S pecifies the key value which will be used for the search.
/TagSearch
URL
GET
Method
https://online.wonderware.com/s/ik97r5/apis/historian
/v2/TagSearch
?q=r&kn=source&kv=atron
TagExtendedProperties
Description Retrieves both standard and extended properties for a tag.
/TagExtendedProperties
URL
GET
Method
Hourly
0 UTC
720 UTC+ 12
-120 UTC-02
-480 UTC-08
-540 UTC-09
-660 UTC-11
Retrieval examples
You can send retrieval requests to the Historian Dat a RES T AP I from any modern web browser and from
ODat a client-side tools. Examples of such tools include Microsoft Excel (2013, 2016, or Office 365), and
Business Intelligence (B I) systems, such as Tableau and Microsoft Power BI.
Click below to see query examples using specific tools:
Browser query examples (see " Retrieve data via brows er query" on page 230)
Postman query examples (see "Retrieve data using Postman" on page 231)
Excel query examples (see "Retrieve data using Excel" on page 233)
PowerBI query example (see "Retrieve data using PowerBI" on page 236)
Note: Retrieval endpoints are unique for each Insight solution. The following examples use the endpoint
"https://online.wonderware.com/s/ik97r5", but yours will be different. Learn how to find the
basic-aut hentication retrieval endpoint for your solution.
https://online.wonderware.com/s/ik97r5/apis/historian/v2
For more information, see Res ourc es (see "Retrieval res ourc es" on page 187).
List data source s (tag groups)
This shows the data sources (labeled " TagGroups" in this API) for your Insight solution. If you have
accounts for more than one solution, this shows the data sources for your original Insight solution.
https://online.wonderware.com/s/ik97r5/apis/historian/v2/TagGroups
https://online.wonderware.com/s/ik97r5/apis/historian/v2/Tags
List tag metadata for a data source
This shows metadata for tags in a particular data source. The data source in this example is named
Baytown.
https://online.wonderware.com/s/ik97r5/apis/historian/v2/Tags?$filter=Sou
rce+eq+'Baytown'
List tag values for a data source
This example expands on the last one. It uses a "$filter" clause that specifies a particular tag named
tank_level within the Baytown data source. The result is a list of values for the tank _level tag.
https://online.wonderware.com/s/ik97r5/apis/historian/v2/ProcessValues?$f
ilter=FQN+eq+'Baytown.tank_level'
List tag values with analog summary data for a data source
This example result is a list of values with analog summary for the tank_level tag.
https://online.wonderware.com/s/ik97r5/apis/historian/v2/AnalogSummary?$f
ilter=FQN+eq+'Baytown.tank_level'
Notice that this example us es a fully qualified name ("Baytown.tank_level"), which is a combination
of a data source name ("Baytown") and a tagname ("tank_level").
4. If the Chrome Apps window doesn't open automatically, s elect in the upper-left corner to
open it.
5. To run Postman, select the icon:
http://localhost:32569/historian/v2
2. From the Type dropdown list, select NTLM Authentication [Beta] to specify the authentication to
use.
3. Enter the username and password for a us er account with sufficient privileges to access the API.
4. In the upper-right of the screen, select Send.
https://online.wonderware.com/s/ik97r5/apis/historian/v2/TagGroups?$forma
t=atom
Note: Retrieval endpoints are unique for each Insight solution. This example uses the endpoint
"https://online.wonderware.com/s/ik97r5", but yours will be different. Learn how to find the
basic-aut hentication retrieval endpoint for your solution.
4. Click Use thi s name and password, and specify your Insight user name and password. Click Next.
5. In the Select Tables box, mark the element to include. Click Next.
6. Review the information displayed on Save Data Connection File and Finish and then click Finish.
Excel creates an ODC (OData Connection) file.
7. Specify how and where to place your data in the spreadsheet. Click OK.
5. Specify Ba sic Authentication, and provide your Insight username and password.
6. Click Connect.
7. Power BI shows a preview of your dat a retrieved from Insight.
8. Click Load.
Query examples
Using GET method with Proce ssValues:
Historian/v2/ProcessValues?TagFilter=EngUnit eq ‘rpm’&DurationHours=2
Historian/v2/ProcessValues?$filter=DateTime le
2019-01-15T03:57:29Z&TagFilter=startswith(Description,
‘Pump’)&DurationHours=10
Historian/v2/ProcessValues?$filter=DateTime ge
2019-01-15T03:57:29Z&TagFilter=startswith(FQN, 'testds1')&DurationHours=5
Historian/v2/ProcessValues?TagFilter=endswith('Level',FQN)
Using GET method with AnalogSummary:
Historian/v2/AnalogSummary?TagFilter=EngUnit eq ‘rpm’&DurationHours =2
Historian/v2/AnalogSummary?$filter=EndDateTime le
2019-01-15T03:57:29Z&TagFilter= startswith(Description,
‘Pump’)&DurationHours=10
Historian/v2/AnalogSummary?$filter=StartDateTime ge 2019-01-15T03:57:29Z
and EndDateTime le 2019-01-17T03:50:54.881Z&TagFilter=startswith(Location,
"/Houston/Mixing")
Historian/v2/AnalogSummary?$filter= StartDateTime ge
2019-01-15T03:57:29Z&TagFilter=startswith(FQN,
'testds1')&DurationInHour=5
Historian/v2/AnalogSummary?TagFilter=endswith(FQN, 'Level')
Using GET method with StateSummary:
Historian/v2/StateSummary?$filter=EndDateTime le
2019-01-15T03:57:29Z&TagFilter=startswith(Description, ‘Pump’)&
DurationHours =10
Historian/v2/StateSummary?$filter=StartDateTime ge 2019-01-15T03:57:29Z
and EndDateTime le 2019-01-17T03:50:54.881Z&TagFilter=startswith(Location,
‘/Houston/Mixing’)
Historian/v2/StateSummary?$filter= StartDateTime ge
2019-01-15T03:57:29Z&TagFilter=startswith(FQN, 'testds1')&DurationHours=5
Historian/v2/StateSummary?TagFilter=endswith(FQN, 'Level')
Notes about post-retrieval filtering
Any post-retrieval filtering may require you to also change the data type for a specific the column in the
results list.
For example, suppose you ran this query:
/Historian/v2/ProcessValues?$filter=OPCQuality eq
192&DurationHours=24&Resolution=3600000&TagFilter=
endswith(TagName,'%23testtag')
Then suppos e you wanted to filter the " DateTime" column to include only yesterday's dat e. You must
change the data type of the Dat eTime column first, and then select the date you want:
1. Right -click the "DateTime" column header, select Change Type. and then click Date/Time.
2. Right -click the "DateTime" column and choose Ye sterday from the displayed list.
Server=localhost:32569
Three Ways To Query the Source
You can query the source using one of these options:
Use a SQL-style query. For example:
http://Server1:32569/Historian/v1/Events?$filter=Source_Area+eq+%27Sit
e2%27+and EventTime+ge+datetimeoffset%272014-08-10T05:56:21.302Z%27
Note: For queries from a web browser, use "%20" to indicate a space. Us e "%27" to indicate a
single quote.
If you are using the JS ONView viewer in the Chrome browser, you can use a plus sign (+) to indicate
a space to make the URI string more readable.
Use an SQL syntax used within the URL. For example, this is equivalent to the other two queries
above:
http://Server1:32569/Historian/v1/Events?sql=select+*+from
Events+where
Source_Area=%27ite2%27+and+EventTime+>=+%272014-08-10T05:56:21.302Z%27
Retrieval errors
The ODat a error codes listed in the following t able may be returned by an operation on any of the storage
services.
MissingRequiredQueryParamet er Bad Request (400) A required query parameter was not specified
for this request.
UnsupportedQueryParamet er Bad Request (400) One of the query parameters specified in the
request URI is not supported.
InvalidQueryParameterValue Bad Request (400) An invalid value was specified for one of the
query parameters in the request URI.
OutOfRangeQueryParameterV alue Bad Request (400) A query parameter specified in the request URI
is outside the permissible range.
RequestUrlFailedToParse Bad Request (400) The url in the request could not be pars ed.
InvalidUri Bad Request (400) The requested URI does not repres ent any
resource on the server.
InvalidHttpVerb Bad Request (400) The HTTP verb specified was not recognized by
the server.
OutOfRangeInput Bad Request (400) One of the request inputs is out of range.
InvalidInput Bad Request (400) One of the request inputs is not valid.
ResourceNotFound Not Found (404) The specified resource does not exist.
OperationTimedOut Internal Server E rror The operation could not be c omplet ed within the
(500) permitted time.