Historian Retrieval
Historian Retrieval
Historian Retrieval
Historian
Retrieval Guide
Version 17.0.18000
March 2017
© 2017 Schneider Electric Software, LLC. 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 Schneider Electric Soft ware, LLC. 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, Schneider Electric
Software, LLC 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 Schneider
Electric Software, LLC. The software described in this documentation is furnished under a license
agreement. This software may be used or copied only in accordance wit h the terms of such license
agreement.
ArchestrA, A vantis, DYNS IM, eDNA, EYESIM, Foxboro, Foxboro E vo, I/A S eries, InBatch, InduS oft,
InStep, IntelaTrac, InTouch, PIPEPHASE, PRiSM, PRO/ II, PROVIS ION, ROMeo, Schneider Electric,
SIM4ME, SimCentral, SimSci, Skelta, SmartGlance, Spiral Soft ware, VIS UAL FLA RE, WindowMaker,
WindowViewer, and Wonderware are trademarks of Schneider Electric SE, its subsidiaries, and
affiliated companies. An extensive listing of Schneider Electric Soft ware, LLC trademarks can be found
at: http://software.schneider-electric.com/legal/trademarks/. All other brands may be trademarks of
their respective owners.
Schneider Electric Soft ware, LLC
26561 Rancho Park way South
Lake Forest, CA 92630 U.S.A.
(949) 727-3200
http://software.schneider-electric.com/
Publication date: 4/3/2017
Contact Us
Contact Schneider Electric Software Technical Support
Avanti s Technical Support
Listing of regional and local country contacts: http://software.schneider -electric.com/support/avantis/
Technical support: http://softwares upport.schneider-electric.com/
For A vantis.PRO, A vantis Approvals, Avantis.DSS, and Condition Manager:
Email: [email protected]
Phone (8:30 a.m. to 5:00 p.m. Monday to Friday, Eastern Time):
o Toll-Free U.S. and Canada: 1-888-262-7111
o Toll-Free EMEA: 1-800-4670-6466
o Direct dial: 1-905-632-0635
For A vantis. XA:
Email: [email protected]
Phone (8:30 a.m. to 5:00 p.m. Monday to Friday, Eastern Time):
o Toll-Free U.S. and Canada: 1-800-991-8000
o Toll-Free EMEA: 1-800-4670-6466
o Direct dial: 1-905-632-4122
SimSci Technical Support
Listing of regional and local country contacts: http://software.schneider -electric.com/support/simsci/
Technical support: http://softwares upport.schneider-electric.com/
Email U.S. and Canada: [email protected]
Phone (USA 8:00 a.m. to 5:00 p.m. Central Time)
o Toll-Free U.S. and Canada: 1-800-746-7241
Skelta Technical Support
Email: [email protected]
Phone:
o U.S.: 1-678-306-4110 Option 3
o India: 91-80-4060-2600 Option 3
Wonderware Technical Support
Listing of regional and local country contacts: https://www.wonderware.com/contact/contact -support/
Technical support: http://softwaresupport.schneider-electric.com/
Priority email for Customer FIRS T Members: custfirstsupport @wonderware.com
Email for customers without a support agreement: [email protected]
Phone
o Toll-Free North America and Latin Americ a: 1-800-966-3371
o Direct dial: 1-949-639-8500
InStep Technical Support
Cont act page: http://www.instepsoftware.com/contact-us
Technical support: https://support.instepsoft ware.com/
Email: [email protected]
Phone (USA 8:00 a.m. to 5:00 p.m. Central Time)
o 1-312-894-7870
Schneider Electric – Smart Water Software Technical Support
Help desk email: [email protected]
Help desk telephone hotline: +45 88 30 20 77 (09:00 to 16:00 Monday to Thurs day, Friday 09:00 to
15:00, Central European Time)
Contact Schneider Electric Software Learning Services
Cont act Software Learning Services for assistance regarding classes, schedule, offerings, frequently
asked questions, tuition, policies, and more.
Email: [email protected]
Toll-Free U.S. and Canada: 1-866-998-7246
Direct: 1-949-639-8508
Fax: 1-949-639-1847
Wonderware Historian Retrieval Guide
Contents
Welcome .................................................................................................................................. 11
Wonderware Historian Documentation Set ................................................................................ 11
Version 17.0.18000 5
Wonderware Historian Retrieval Guide Contents
6 Version 17.0.18000
Contents Wonderware Historian Retrieval Guide
Version 17.0.18000 7
Wonderware Historian Retrieval Guide Contents
8 Version 17.0.18000
Contents Wonderware Historian Retrieval Guide
Version 17.0.18000 9
Wonderware Historian Retrieval Guide Contents
10 Version 17.0.18000
Wonderware Historian Retrieval Guide
Welcome
This guide describes how to retrieve data that is stored by a Wonderware 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 cont ent (sets of tags and defined timeframes ), and can share, embed, and
download the results. Historian InSight is installed as a part of Wonderware Historian.
Historian SDK.
Tools that use the RES T ODat a interface.
Version 17.0.18000 11
Wonderware Historian Retrieval Guide
C HAPTER 1
About Data Retrieval
Through the Data Retrieval subsystem, Wonderware 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 Wonderware 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.
In This Chapter
Data Retrieval Subsystem Features ............................................................................................... 13
History Blocks: A SQL Server Remot e Dat a Source ........................................................................ 14
Retrieval subsystem...................................................................................................................... 14
About the Wonderware Historian OLE DB Provider ......................................................................... 14
Wonderware Historian I/O Server................................................................................................... 17
Using SELE CT to Retrieve Data .................................................................................................... 17
Version 17.0.18000 13
Wonderware Historian Retrieval Guide About Data Retrieval
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).
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 Wonderware 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.
14 Version 17.0.18000
About Data Retrieval Wonderware Historian Retrieval Guide
To access Wonderware Historian historical data using OLE DB, any COM -based client application
must connect directly to the SQL Server and then specify to use the Wonderware Historian OLE DB
provider in the syntax of the query.
When you execute a query and specify the Wonderware 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 Wonderware
Historian OLE DB provider. The Wonderware Historian OLE DB provider will then interfac e wi th the
retrieval service to locat e the data store, extract the requested information, and ret urn the data to the
Microsoft SQL Server as a rowset. Microsoft SQL Server will perform any other processing required on
the data and return the data to the client application as a result set and a set of output parameters, if
applicable.
The Wonderware Historian OLE DB provider must be present on the server running Microsoft SQL
Server. The set of Transact-SQL operations that can be used to retrieve data in the his tory blocks
depends on the capabilities of the Wonderware Historian OLE DB provider.
For more information on OLE DB, see your Microsoft documentation.
Data access from the history blocks is made possible by SQL Server's OLE DB provider technology.
Client applications must connect directly to the Microsoft SQL Server and then specify to use the
Wonderware 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
Version 17.0.18000 15
Wonderware Historian Retrieval Guide About Data Retrieval
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
Database Reference.
Legacy Event Data Extension Tables
These are legacy (backward compatible) extension tables for events:
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 Wonderware Historian OLE DB provider as the linked ser ver. Use this
name to specify the Wonderware Historian OLE DB provider in a query.
To perform joins between the legacy analog history tables and discrete history tables, the installation
program also creates an alias for the same Wonderware 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
16 Version 17.0.18000
About Data Retrieval Wonderware Historian Retrieval Guide
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).
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 Wonderware Historian OLE DB
provider to retrieve history data:
Using the Four-Part Naming Convention on page 18
Using a Wonderware Historian OLE DB Provider View on page 19
Using the OPE NQUERY Function on page 19
Using the OPE NROWSET Function on page 20
You should use the four-part name or a provider view to specify the extension table, whenever
possible. However, there are instances when the OPENQUE RY or OPE NR OWSET function must be
used, such as for queries on wide tables.
Version 17.0.18000 17
Wonderware Historian Retrieval Guide About Data Retrieval
For general information on creating SQL queries, see your Microsoft SQL Server documentation.
In the case of four-part queries, SQL Server produces the statement that is sent to the Wonderware
Historian OLE DB provider from the statement that the us er executes. Sometimes this produc ed
statement is incorrect, too complex, or lacks portions of the WHERE clause required for the
Wonderware Historian OLE DB provider to return dat a.
A typical error message when executing unsupported syntax is:
18 Version 17.0.18000
About Data Retrieval Wonderware Historian Retrieval Guide
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 o perating system.
Note: Backward compatibility views are named according to the v_P roviderTableName convention.
For example:
Version 17.0.18000 19
Wonderware Historian Retrieval Guide About Data Retrieval
yyyy-mm-dd hh:mm:ss.fff
For example:
2001-01-01 09:00:00.000
You cannot use variables in an OPENQUERY statement. For more information, see Using Variables
with the Wide Table.
GROUP BY Yes No
20 Version 17.0.18000
About Data Retrieval Wonderware 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 returning the vValue column. This restriction applies if you are using the four-part
naming convention or an extension table view.
For example:
Version 17.0.18000 21
Wonderware Historian Retrieval Guide About Data Retrieval
However, it is more efficient to use an INNE R REMOTE JOIN to achieve the same results. For more
information, see Using an INNER REMOTE JOIN.
OR Clause Limitations
You cannot use the OR clause to specify more than one condition for a time domain extension. For
more information, see Wonderware Historian Time Domain Extensions on page 26.
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:
22 Version 17.0.18000
About Data Retrieval Wonderware Historian Retrieval Guide
ORDER BY t.TagName
You can only use simple joins bet ween SQL Server tables and the Wonderware Historian OLE DB
extension tables. Joins typically require us e of the INNE R REMOTE JOIN syntax.
For an example of the INNE R REMOTE JOIN syntax, see Using an INNE R REMOTE JOIN.
Using a sub-SELE CT with a query on a normal SQL Server table and an extension table should be
avoided; it is very inefficient due to the way SQL Server executes the query. For example:
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 rec eived 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.
Version 17.0.18000 23
Wonderware Historian Retrieval Guide About Data Retrieval
The CONVE RT function is not support ed on the vValue column in an OPENQUE RY 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.
24 Version 17.0.18000
About Data Retrieval Wonderware Historian Retrieval Guide
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
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.
Version 17.0.18000 25
Wonderware Historian Retrieval Guide About Data Retrieval
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'
AND wwFilter = 'ToDiscrete(5.0,>)'
AND wwVersion = 'Latest'
AND DateTime >= @StartDate
AND DateTime <= @EndDate
AND StartDateTime >= @StartDate
SQL Server returns an error for a query that contains a comparis on 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.
26 Version 17.0.18000
About Data Retrieval Wonderware Historian Retrieval Guide
wwCycleCount wwStateCalc
wwE dgeDet ection wwTimeDeadband
wwFilter wwTimeZone
wwInt erpolationType wwV alueDeadband
wwOption wwV ersion
wwQualityRule wwTimeStampRule
wwResolution wwV alueS elector
wwRetrievalMode
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:
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 support ed.
For general information on creating SQL queries, see your Microsoft SQL Server documentation.
Version 17.0.18000 27
Wonderware 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.
In This Chapter
Understanding Retrieval Modes ..................................................................................................... 29
Understanding Retrieval Options ................................................................................................... 88
Cyclic Retrieval
Cyclic retrieval is the retrieval of stored data for the 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 Wonderware Historian.
Version 17.0.18000 29
Wonderware 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 Wonderware Historian ret urns 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 Wonderware 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
Wonderware Historian Administration Guide.
The default retrieval mode is cyclic for ret rieval 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 43).
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 dat a for three cycle boundaries at TC0, TC1, and TC2. Each
dot in the graphic represents an actual dat a point stored on the historian. From these points, the
following are ret urned:
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
30 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
You can use various parameters to adjust which values are returned in c yclic retrieval mode. For more
information, see the following sections:
Cycle Count (X Values over Equal Time Intervals) (wwCycleCount) on page 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Timestamp Rule (wwTimestampRule) on page 106, for Wonderware Historian 9.0 and above
Qualit y Rule (wwQualit yRule) on page 111
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 17.0.18000 31
Wonderware 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 Ret rieval - Initial Values on page 36.
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 retrieval of only the changed values for a tag(s)
for the given time int erval. 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.
32 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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 96
Value Deadband (wwValueDeadband) on page 100
History Version (wwVersion) on page 103
Qualit y Rule (wwQualit yRule) on page 111
To use the delta retrieval mode, set the following parameter in your query.
wwRetrievalMode = 'Delta'
Version 17.0.18000 33
Wonderware 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 returned 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 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 96 and Value Deadband
(wwValueDeadband) on page 100.
34 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Version 17.0.18000 35
Wonderware Historian Retrieval Guide Data Retrieval Options
36 Version 17.0.18000
Data Retrieval Options Wonderware 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 preceding data point at 00:16. Because there is no change in the value at
00:27 from the value at 00:24, the data point appears on the chart but does not a ppear 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.
Version 17.0.18000 37
Wonderware Historian Retrieval Guide Data Retrieval Options
By using full ret rieval in conjunction with storage without filtering (that is, no delta or cyclic storage
mode is applied at the historian), you can retrieve all values that originat ed from the plant floor dat a
source or from another application.
Full retrieval best repres ents the process measurements recorded by the Wonderware Historian.
However, it creates a higher load for the server, the network 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 103
Qualit y Rule (wwQualit yRule) on page 111
38 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Full retrieval mode handles initial values the same way as delta mode. For more information on initial
values, see Delta Retrieval - Initial Values on page 36.
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 "stair-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 t han would be returned if
interpolation was not applied.
By default, interpolated retrieval uses the interpolation setting specified for the tag in the Wonderware
Historian. This means that if a tag is set to use stair-step interpolation, interpolated retri eval 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 limitations of cyclic retrieval in
that it may not accurately represent the stored process data.
Data is retrieved in interpolated mode with a start time of TC 0 and an end time of TC2. The res olution
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 dat a 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 P8.
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 17.0.18000 39
Wonderware 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 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Interpolation Type (wwInterpolationType) on page 104
Timestamp Rule (wwTimestampRule) on page 106
Qualit y Rule (wwQualit yRule) on page 111
To use the interpolated mode, set the following parameter in your query.
wwRetrievalMode = 'Interpolated'
40 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Version 17.0.18000 41
Wonderware Historian Retrieval Guide Data Retrieval Options
42 Version 17.0.18000
Data Retrieval Options Wonderware 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 prec edes the 00:30 cycle boundary at 00:29, the NULL is ret urned 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 the cyc le boundary.
If a valid value precedes a cycle boundary, but is followed by a NULL value after the cycle boundary,
no interpolation will be used and wwInterpolationType will be set to S TAIRS TEP for that value.
For the " best fit" retrieval mode, the total time for the query is divided int o even sub -periods, and then
up to five values are returned 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 17.0.18000 43
Wonderware Historian Retrieval Guide Data Retrieval Options
"Best fit" retrieval allows for a compromise bet ween delta retrieval and cyclic retrieval. For example,
delta ret rieval can accurately represent a process over a long period of time, as shown in the following
trend. However, to achieve this represent ation, 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.
44 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
"Best fit" retrieval allows for faster retrieval, as typically achieved by using cyclic retrieval , plus the
better represent ation typically achieved by using delta 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 17.0.18000 45
Wonderware 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 resolution has
been set in such a way that the historian returns data for two complet e cycles starting at T C0 and TC1
and an incomplete cycle starting at TC2. P1 to P 12 represent actual dat a 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 th e data between P 7 and P8.
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 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Interpolation Type (wwInterpolationType) on page 104
Qualit y Rule (wwQualit yRule) on page 111
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.
46 Version 17.0.18000
Data Retrieval Options Wonderware 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 will 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 39.
Version 17.0.18000 47
Wonderware 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 us er 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-weight ed 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 data values. For the 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 between values are weight ed. For a tag that 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:
48 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
(((P1 + P2) / 2) x (T2 - T1)) + (((P 2 + P3) / 2) x (T3 - T2)) + (((P 3 + P4) / 2) x (T4 - T3 )) / (T4 - T1) =
A verage
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 ret rieval mode wit h
a cycle count of 1 ret urns data much faster than the AVG aggregate, and us ually more accurat ely due
to the time weighting. The E vent subsystem also returns a simple statistical average.
A verage retrieval ret urns 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 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 using regular cyclic retrieval.
The following illustration shows how the time -weighted average is calculated for an analog tag that
uses linear interpolation.
Version 17.0.18000 49
Wonderware Historian Retrieval Guide Data Retrieval Options
Data is retrieved in average 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 two complet e cycles starting at T C0 and TC1
and an incomplete 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
Server 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.
Results are calculated as follows:
The "initial value" returned at the query start time (TC0) is the time-weighted average of the points
in the last cycle preceding TC0.
The value returned at TC1 is the time-weighted average of the points in the cycle starting at TC0.
The value returned at the query end time (TC2) is the time-weighted average of the points in the
cycle starting at TC1.
To understand how the time-weighted average is calculated, obs erve the last cycle as an example.
First, the area under the curve must be calculated. This curve is indicated by the red line through P 6,
P7, P8 and P C2, where P C2 represents the interpolated value at time TC2 using points P 8 and P 9. The
data gap caused by the I/O Server disconnect does not contribute anything to this area. If a quality rule
of "good" has been specified, then points with doubt ful quality will not contribute anything to the area,
either.
To understand how the area is calculated, consider points P 6 and P 7. The area contribution between
these two points is calculated by multiplying the arithmetic average of value P 6 and value P 7 by the
time difference between the two points. The formula is:
((P6 + P7) / 2) x (T7 - T6 )
When the area for the whole cycle has been calculated, the time-weighted average is calculated by
dividing that area by the cycle time, less any periods within the cycle that did not contribut e anything to
the area calculation. The result is returned at the cycle end time.
If you take a closer look at points P 4 and P5 in the example, you can see that the red line through point
P4 is parallel to the x-axis. This is because P 5 represents a NULL, which cannot be used to calculate
an arithmetic average. Instead, the value P 4 is used for the whole time period between points P 4 and
P5.
The area calculation is signed. If the arithmetic average between two points is negative, then the
contribution to the area is negative.
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 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Interpolation Type (wwInterpolationType) on page 104
Timestamp Rule (wwTimestampRule) on page 106
Qualit y Rule (wwQualit yRule) on page 111
50 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
To use the average mode, set the following parameter in your query.
wwRetrievalMode = 'Average'
Version 17.0.18000 51
Wonderware Historian Retrieval Guide Data Retrieval Options
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 = STA RT, the final value is calculated by pe rforming 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.
52 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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.
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 dat a 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 P 14.
The minimum value for the "phantom" cycle starting at TCP is returned as the initial value at TC0. Point
P18 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 markers on the graph are returned (P 10, P13, and
P17).
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, becaus e 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 90
Version 17.0.18000 53
Wonderware Historian Retrieval Guide Data Retrieval Options
To use the minimum mode, set the following parameter in your query:
wwRetrievalMode = 'Min'
or
wwRetrievalMode = 'Minimum'
54 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Version 17.0.18000 55
Wonderware Historian Retrieval Guide Data Retrieval Options
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 "phant om" 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 36.)
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.
56 Version 17.0.18000
Data Retrieval Options Wonderware 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 the preceding cycle, which is the data point at 00:09. In the two subsequent cycles,
the minimum values are at 00:22 and 00:38. The quality for these two values is set to 4288 (4096 +
192). The remaining data points are excluded becaus e they are not minimums. In addition, the first
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.
Version 17.0.18000 57
Wonderware Historian Retrieval Guide Data Retrieval Options
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 dat a 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 P 14.
The maximum value for the "phantom" cycle starting at TCP is returned as the initial value at TC0. Point
P18 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 markers on the graph are returned (P 12, P13, and
P15).
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, becaus e 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 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Qualit y Rule (wwQualit yRule) on page 111
58 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
To use the maximum mode, set the following parameter in your query:
wwRetrievalMode = 'Max'
or
wwRetrievalMode = 'Maximum'
Version 17.0.18000 59
Wonderware 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 phantom
cycle start 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 alt ered. Apart from the initial value, all points returned are delt a points. (For more
information on initial values, see Determining Cycle Boundaries on page 139.)
If a point occurs exactly on the query end time, that point is returned wit h the partial cycle bit, 4096, set
in quality detail. If there is more than one such point, only the first point is returned.
60 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
As an example of how maximum retrieval mode handles NULLs, consider the following query:
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.
Version 17.0.18000 61
Wonderware Historian Retrieval Guide Data Retrieval Options
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 thes e two values is set to 4288 (4096 +
192). The remaining data points are excluded becaus e 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 the 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 tag. For
example, 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 cyc le count.
Integral retrieval only works with analog tags. For all other tags, normal cyclic results are returned.
You can use various parameters 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 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Interpolation Type (wwInterpolationType) on page 104
62 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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.
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 168.
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 = STA RT, 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.
Version 17.0.18000 63
Wonderware Historian Retrieval Guide Data Retrieval Options
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 amo unt, and a sharp increase 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.
64 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
For point P 6, there is no prior point with which to perform a slope calculation. Instead, the slope of the
flat line going through the point (that is, the value 0) is calculated. At the time of P 5, NULL is returned.
The quality detail and OPC quality returned wit h a slope point is always directly inherited from the point
that also provides the time stamp. In this example, this means that point P 2 provides the qualities for
the slope point returned at the query start time, TS.
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 103
Qualit y Rule (wwQualit yRule) on page 111
wwRetrievalMode = 'Slope'
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 139.)
At 08:01:17.947 the tag has two delta points, so a slope is calculated and retu rned for the 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.
Version 17.0.18000 65
Wonderware Historian Retrieval Guide Data Retrieval Options
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 aft er the query start time.
A final value is always generated. 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 aft er the query end time.
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
Wonderware Historian for each 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 indicator 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 reac hes the 9,999th value, the
counter rolls back to 0. Therefore, a counter value of 9,900 at one time and a value of 100 at a later
time means that you have produced 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 ret rieval 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.
66 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Counter retrieval also works with floating point counters, whic h 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 Qualit y Rule (wwQualityRule) on page 111. When
a rollover has occurred in the calculation cycle, a special quality detail of 212 is returned in all
non-NULL cases.
CTU counters 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 count ers will count up
to the upper limit and "rollover" to the lower limit on the next increment. If these 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 counter, the same rules apply, but the range of values is -32768 to 32767 as "signed" and 0 to
65535 for an "unsigned".
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 represented by the
markers P 1 through P 12. Of these points, eleven represent normal analog values. The point P 9
represents a NULL due to an I/O Server disconnect, which causes a gap in the data bet ween P 9 and
P10. 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.
Version 17.0.18000 67
Wonderware Historian Retrieval Guide Data Retrieval Options
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, because there is no counter value 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 the 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.
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 dat a 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 cont ribut es 1 to the counter value, and that 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 rollo vers.
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 rollover and is counted as such.
68 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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 convey or 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
detected until the rollover occurs.
You can use various parameters 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 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Timestamp Rule (wwTimestampRule) on page 106
Qualit y Rule (wwQualit yRule) on page 111
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.
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 gap 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_FILTERE DPOINT applied to the quality detail.
Version 17.0.18000 69
Wonderware Historian Retrieval Guide Data Retrieval Options
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.
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 into a reactor, and you want to know
the average amount of time the valve was in the open position during the last hour. ValueState ret rieval
can return the shortest, 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 during each 1-hour cycle. This
information is suitable for trend display.
If you don’t specify a state, ValueState ret rieval returns one row of information for each value that the
tag was in during each cycle. For example, this would ret urn 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 retrieval 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 the 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 (wwSt ateCalc) on page 118.
70 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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 returns two 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 ti mestamp of
the query start time.
For TC1, one row is returned for the "on" state. The "on" state occurred 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 bet ween 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 foll owing is returned:
For TC0, the query returns two values (one for the "on" state and one for the "off" 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 to the total time. The st ate was "off" one time
during the cycle for two seconds completely within the cycle boundary.
Version 17.0.18000 71
Wonderware Historian Retrieval Guide Data Retrieval Options
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 cycle 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 90
Resolution (Values Spaced Every X ms) (wwResolution) on page 92
History Version (wwVersion) on page 103
Timestamp Rule (wwTimestampRule) on page 106
Qualit y Rule (wwQualit yRule) on page 111
State Calculation (wwStateCalc ) on page 118
To use theValueState retrieval mode, set the followin g parameter in your query.
wwRetrievalMode = 'ValueState'
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 72
ValueState Retrieval Query 2: Minimum Time in State for a Single Tag on page 73
ValueState Retrieval Query 3 on page 73
ValueState Retrieval Query 4 on page 74
ValueState Retrieval Query 5 on page 74
ValueState Retrieval Query 6: Querying State Summary Values on page 75
72 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Version 17.0.18000 73
Wonderware Historian Retrieval Guide Data Retrieval Options
74 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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.
Version 17.0.18000 75
Wonderware Historian Retrieval Guide Data Retrieval Options
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 ret rieval uses the time between consec utive
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 rows 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 indicate that
the previous state is a contained state.
If no roundtrip state is found within the cycle for a support ed 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.
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 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 contained time in the two states are ret urned. 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. The following is returned:
76 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
For TC0, the query returns two 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 within 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 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 the values that must be ret urned in the RoundTrip retrieval
mode. For more information, see the following sections:
Timestamp Rule (wwTimestampRule) on page 106
Qualit y Rule (wwQualit yRule) on page 111
State Calculation (wwStateCalc ) on page 118
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.
Version 17.0.18000 77
Wonderware Historian Retrieval Guide Data Retrieval Options
The first two rows are for the "phantom" cycle leading up to the query start time and have a timestamp
of the query start time.
The second two rows show the average amount of time for each state and have a timestamp of the
query end time (t he default).
Compare these results to same basic query that instead uses RoundTrip ret rieval:
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 retrieval mode, the NULL state is treated as a valid distinct value. This allows
you to analyze round trips for disturbances.
78 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
When det ecting events, it is useful to pinpoint rows in a result set where the satisfaction of criteria in a
WHERE clause changed from true to false, or vice versa. For example, you may want to know when
the level of a tank went above 5 feet. The WHERE clause in a query for this example might be
TA NKLEVEL > 5. As the tank level approaches 5 feet, the criterion does not return true. Only when the
level crosses the line from not satisfying the criterion to satisfying it, does the event actually occur. This
imaginary "line" where the change occurs is called the edge.
Over a period of time, there may be many instanc es where the criteria cross the "edge" from being
satisfied to not satisfied, and vice-versa. The values on either side of this "edge" can be detected if you
configure your event tag to include this information. There are four possible options for edge detection:
none, leading, trailing, or both. You will get differing results based on which option you use:
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 (return 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.
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 (ToDiscret e) on
page 121.
For more information on event detection with the Classic Event subsystem, see Classic Event
Subsystem in the Wonderware 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 comparison operator used against the value.
Version 17.0.18000 79
Wonderware Historian Retrieval Guide Data Retrieval Options
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.
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
80 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
2001-12-02 10:01:58.000 58
If Leading is specified as the parameter 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 (ret urned 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
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Analog Tags on page 79. 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 result 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 (ret urn ed 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.
Version 17.0.18000 81
Wonderware Historian Retrieval Guide Data Retrieval Options
The query returns only the two values that were the first to fail the criteria in the WHE RE clause for the
time period specified:
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 79. Notice that even though the original query returned ten recorded rows for
each value, the edge det ection only ret urns the first row recorded after the event criteria ret urned false.
If Bot h is specified as the parameter in the edge detection extension, all rows satisfying both the
leading and trailing conditions are returned.
The following query selects values of "SysTimeS ec" from th e History table that meet bot h the Leading
and Trailing criteria 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: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 79. Notice that value of the first row in the original query is returned in the result
set.
Edge detection for discrete tags operat es diffe rently than for analog tags. For example, assume the
following discrete tags are stored.
82 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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:
Version 17.0.18000 83
Wonderware Historian Retrieval Guide Data Retrieval Options
AND SysPulse = 1
AND MyPulse = 1
AND wwRetrievalMode = "Delta"
AND wwEdgeDetection = "None"
')
The results are:
If Leading is specified as the parameter 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 (ret urned 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.
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).
84 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
AND MyPulse = 1
AND wwEdgeDetection = "Leading"
')
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Discrete Tags on page 82. If you look at the diagram, you might think that a row could be returned at
00:03: 00, but bec ause 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 ex tension, the only rows in the result 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 (ret urned 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).
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).
Version 17.0.18000 85
Wonderware Historian Retrieval Guide Data Retrieval Options
Compare these results with the same query using no edge detection, as shown in Edge Detection for
Discrete Tags on page 82. If you look at the diagram, you might think that a row could be returned at
00:03: 00, but bec ause 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 Bot h 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.
86 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Compare these results with the same query using no edge detection, as shown in the Edge Det ection
for Discrete Tags on page 82.
Predictive Filter
Wonderware Historian supports predictive retrieval. Beginning with Wonderware 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 future releases.
With Wonderware Historian, you can create a query based on data you have stored to predict
additional values in a trend. Historian returns predictive data based on a "simple linear regression"
(SLR) algorithm.
For example, based on your currently stored values, you could use the predictive retrieval 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 data source, you could us e 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 interpolated results based 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 17.0.18000 87
Wonderware Historian Retrieval Guide Data Retrieval Options
FROM History
WHERE TagName = 'Tag1'
AND DateTime >= '2014-01-01 0:00:00.000'
and DateTime < '2014-01-01 1:00:00.000'
and wwFilter = 'SLR()'
In this example, "SLR" stands for "simple linear regression," the algorithm used by Wonderware
Historian to analyze currently stored values and predict other values wit hin the detected trend.
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 q uery.
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 88.
Interpolation Type
on page 100
on page 106
page 118
page 119
page 96
103
111
Interpolated Retrieval on Y Y Y Y Y Y Y Y
page 39
Best Fit Retrieval (see Y Y Y Y Y Y Y Y
"Best Fit Retrieval" on
page 43)
Average Ret rieval on Y Y Y Y Y Y Y Y
page 48
Minimum Retrieval on Y Y Y Y Y Y
page 52
Maximum Retrieval on Y Y Y Y Y Y
page 57
88 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Interpolation Type
on page 100
on page 106
page 118
page 119
page 96
103
111
Integral Retrieval on Y Y Y Y Y Y Y Y
page 62
Slope Retrieval on page Y Y Y Y
64
Counter Retrieval on Y Y Y Y Y Y
page 66
ValueState Retrieval on Y Y Y Y Y Y Y
page 70
RoundTrip Retrieval on Y Y Y Y Y Y Y
page 76
* - only on Wonderware Historian 9.0 and later
** - only Wonderware 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:
Version 17.0.18000 89
Wonderware Historian Retrieval Guide Data Retrieval Options
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 support ed.
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 cycl es 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 dat a points may be returned for a cycle, depending on the
nature of the dat a.
The length of eac h cycle (the "resolution" of the returned values) is calc ulated 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 Every X ms) (wwResolution) on page 92.
This option is relevant in the following retrieval modes:
Cyclic Retrieval on page 29
Interpolated Retrieval on page 39
"Best Fit" Retrieval (see "Best Fit Retrieval" on page 43)
Average Ret rieval on page 48
Minimum Retrieval on page 52
Maximum Retrieval on page 57
Integral Retrieval on page 62
Counter Retrieval on page 66
ValueState Retrieval on page 70
RoundTrip Retrieval on page 76
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 return 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.
If wwRes olution and wwCycleCount are set to 0, then a default of 100000 cycles are chosen.
90 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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 states are retur ned for the first
cycle.
For ValueState retrieval, if the end time of the cycle is excluded, no states are returned for the last
cycle.
Version 17.0.18000 91
Wonderware Historian Retrieval Guide Data Retrieval Options
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 physical 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 E qual Time Intervals) (wwCycleCount) on page 90.
This option is relevant in the following retrieval modes:
Cyclic Retrieval on page 29
Interpolated Retri eval on page 39
92 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Version 17.0.18000 93
Wonderware Historian Retrieval Guide Data Retrieval Options
Simple use of Cycle s not defined, but similar simple Phantom cycle used to calculate
phantom 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 returned an additional row at the qu ery 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.
94 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
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 dat a
stamped at the query start time. This query, however, must specify a time difference between the st art
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 specified interval, 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 D ateTime
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 result:
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 same offset as the time stamp returned in the 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 Start DateTime column would return '2009-10-16 07:00:00'
making it easy to interpret the result.
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 res ult is therefore calculated for the specified time interval between 8 a.m. and 9
a.m. In this example, the new StartDat eTime column would return the same time stamp as the
DateTime column, '2009-10-16 08:00:00', again making it easier to interpret the result.
Version 17.0.18000 95
Wonderware Historian Retrieval Guide Data Retrieval Options
For retrieval modes for which cycles are defined, the Start DateTime column returns the cycle start
time. These modes are:
Cyclic Retrieval on page 29
Interpolated Retrieval on page 39
"Best Fit" Retrieval (see "Best Fit Retrieval" on page 43)
Average Ret rieval on page 48
Minimum Retrieval on page 52
Maximum Retrieval on page 57
Integral Retrieval on page 62
Counter Retrieval on page 66
ValueState Retrieval on page 70
RoundTrip Retrieval on page 76
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 168.
96 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Data is retrieved for the time period starting with TS and ending with TE. All points in the graphic
represent data values stored on the historian. The grey 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
other points are not returned because they fall wit hin a deadband.
Note: All of these example queries return dat a values for the analog tag 'SysTimeSec'.
Version 17.0.18000 97
Wonderware Historian Retrieval Guide Data Retrieval Options
98 Version 17.0.18000
Data Retrieval Options Wonderware Historian Retrieval Guide
Version 17.0.18000 99
Wonderware Historian Retrieval Guide Data Retrieval Options
Data is retrieved for the 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, which
starts anew with every returned value. Only the green points (P 2, P5, P6, P7, P9, P10, P11) are ret urned.
The other points are not returned 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.
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
The Wonderware Historian allows you to overwrite a stored tag value with later versions of the value.
The original version of the value is still maintained, so that effectively, multiple versions of the tag value
exist at the same point in time.
When ret rieving data, you can specify whether to retrieve the originally stored version or the latest
version that is available. To do this, set the history version option to "Original" for the original version or
"Latest" for the lat est available version. If you do not specify the version, the latest version is returned.
To distinguish between a latest value and an original value, the historian returns a special QualityDetail
value of 202 for a latest point with good quality.
This option is relevant in all ret rieval modes.
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 distinguis h between an actual latest value and an original value, a special QualityDetail
of 202 is returned for a good, latest point.
For example:
For various retrieval modes, you can control how analog tag values at cycle boundaries are calculated
if there is no actual value stored at that point in time. The options are as follows:
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 bet ween the
last stored value before the boundary and the first stored value after the bo undary. 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:
Interpolated Retrieval
"Best Fit" Retrieval
Average Ret rieval on page 48
Integral Retrieval on page 62
The quality of an interpolated point is determined by the wwQualityRule setting. For more information,
see Qualit y Rule (wwQualityRule) on page 111.
For various cycle-based retrieval modes, you can control whether the returned values are timestamped
at the beginning or at the end of each cycle.
To force a query to timestamp results at the start of a cycle, specify the following in the query:
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
Wonderware Historian.
This option is relevant in the following retrieval modes:
Cyclic Retrieval on page 29 (Wonderware Historian 9.0 and later)
Interpolated Retrieval on page 39
Average Ret rieval on page 48
Integral Retrieval on page 62
If you are using date/time functions and the wwTimeZone parameter, you will need to use the
faaTZgetdate() function.
If the query were to specify OP TIMIS TIC, the counter mode will always return rows with numeric
counter values and good quality. These rows may or may not be precise. The Perc entGood 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 Percent Good 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 counter values that are returned using OP TIMIS TIC quality in the preceding
illustration. The query skips the value to be ret urned 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 q uery 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 qu ery does not summarize data for gaps becaus e there is no way
to know which value to use for the summarization. However, if the query specifies OP TIMIS TIC quality,
the query uses the last known good value for the summarization in the gap. As described for t he
counter retrieval example, the PercentGood column also expresses the quality of the calculated value
in integral ret rieval, so if the PercentGood is anything less than 100, then the returned row may be
incorrect.
Note: Cyclic, Full, Delta, Maximum, Minimum, and BestFit do not have combined qualities; therefore,
the rules are not applied to these modes..
TotalContained: The total amount of time that the tag has been in each unique state for each
cycle, disregarding the occurrences that are not fully contained with the calculation cycle.
PercentContained: The percentage of time that the tag has been in eac h unique state for each
cycle, disregarding the occurrences that are not fully contained with the calculation cycle.
All results except Percent are in milliseconds. Percent is a percentage typically between 0.0 and 100.0.
The percent age can be higher than 100 in certain circumstances.
The nature of the data and how you set the cycle count determines whether 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 alway s 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 results 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 occurrences 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 bet ween consecutive leading edges of any s tate 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 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. (This is the default.)
TotalContained. The total 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.
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.
You need to specify a filter name in the virt ual column wwFilter, with or without an override, to the set
of parameters that are defined for the specified filter. The filters are specified as C-like functions:
parentheses are always required, even when you choose not to override the default parameters by
passing no paramet ers.
The default value for the wwFilter column is ‘NoFilter’. If the query does not specify the wwFilt er
element at all, or if its default value is not overridden, then no filter is applied.
When you use the analog filters in a query that uses wwQualityRule, wwQualityRule is applied first and
wwFilter is applied later. You can only use one filter per query.
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 paramet er 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 valu e > ì + nó
or value < ì – nó.
Time weighted standard deviation is calculated as:
Math.Sqrt( (integralOfS quares - 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 convert 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:
NULLs encountered in the analog value stream are copied unchanged to the discrete value stream.
The quality of each discrete point is copied from the analog point that causes its production. However,
the quality detail for values modified wit h this filter will have the QualityDetail flag 0x2000 (value
changed by filter) set. For example, consider the following ValueState query:
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 ToDiscret e() filter is similar to using edge detection for event tags. Edge detection
returns the actual value with a timestamp in history for when a value matched a certain criteria.
The ToDiscrete() filt er 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 threshold times.
Use the ToDiscrete() filt er if you are mostly interested in when something occurred, and not necessarily
the exact value of the event.
For more information on edge detection, see Edge Detection for Events (wwE dgeDetection) on page
78.
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 aggregate ret rieval
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
When the Snap to filter is specified, point values falling inside any of the ranges [Base value –
Tolerance, Base value + Tolerance] will be forced to the base value before the point goes into further
retrieval proc essing. The result is undefined if the base value +/- tolerance exceeds the range of the
double data type. The range is calculated using this expression:
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 to return. See the following
table for how A UTO 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 thes e 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 AnalogSummaryHistory table. Int erpolation 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 calculated 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 (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 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 occurrence 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 Wonderware 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 dat abas e 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.
In This Chapter
Querying the History Table .......................................................................................................... 131
Querying the Live Table .............................................................................................................. 131
Querying the WideHistory Table .................................................................................................. 132
Querying Wide Tables in Delta Retrieval Mode ............................................................................. 133
Querying the AnalogSummaryHistory View .................................................................................. 134
Querying the StateS ummaryHistory View ..................................................................................... 134
Using an Unconventional Tagname in a Wide Table Query ........................................................... 135
Using an INNE R REMOTE JOIN ................................................................................................. 136
Setting Both a Time and Value Deadband for Retrieval ................................................................. 136
Using wwResolution, wwCycleCount, and ww Ret rievalMode in the Same Query ............................ 139
Determining Cycle Boundaries..................................................................................................... 139
Mixing Tag Types in the Same Query........................................................................................... 140
Using a Criteria Condition on a Column of Variant Data ................................................................. 141
Using DateTime Functions .......................................................................................................... 141
Using the GROUP BY Clause...................................................................................................... 143
Using the COUNT() Function ....................................................................................................... 143
Using an Arithmetic Function ....................................................................................................... 144
Using an Aggregate Function ...................................................................................................... 144
Making and Querying Annotations ............................................................................................... 146
Using Comparison Operators with Delta Retrieval ......................................................................... 146
Using Comparison Operators with Cyclic Retrieval and Cycle Count .............................................. 151
Using Comparison Operators with Cyclic Retrieval and Resolution ................................................. 154
Returning Time Bet ween Value Changes ..................................................................................... 157
SELECT INTO from a History Table ............................................................................................. 162
Moving Data from a SQL Server Table to an Extension Table ........................................................ 163
Using Server-Side Curs ors .......................................................................................................... 164
Using Stored Procedures in OLE DB Queries ............................................................................... 165
Getting Data from the OPCQualityMap Table ............................................................................... 165
Using Variables with the Wide Table ............................................................................................ 166
Retrieval Across a Data Gap in Classically Stored Data ................................................................ 166
Returned Values for Non-V alid Start Times .................................................................................. 168
Querying Aggregate Data in Different Ways ................................................................................. 168
Bitwise Retrieval for Process Data ............................................................................................... 170
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 in the Wonderware Historian Dat abase Reference.
Version 17.0.18000 131
Wonderware Historian Retrieval Guide SQL Query Examples
The following query returns the current value of the specified tag. The query uses the remote table
view (Live is used in place of INSQL.Runtime.dbo.Live).
TagName Value
ReactLevel 1145.0
(1 row(s) affected)
The wide extension table is a transposition of the History table. Use the wide history tables any time
you want to find the value of one or more tags over time and need to specify different filter criteria for
each tag.
For more information, see History Tables in the Wonderware Historian Dat abase Reference.
The following query returns the value of two tags from the WideHistory table. The WideHistory table
can only be accessed using the OPE NQUERY function. The "Runtime.dbo." qualifier is optional.
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.
Count
SysPulse 1 192 30 1800000 50
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:
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 i n a query on a wide table. "ReactTemp -2"
and "React Temp+2" are tagnames. Without the delimiters, the pars er would attempt to include the " -2"
and "+2" suffixes on the tagnames as part of the arithmetic operation.
For clarity and maintainability of your que ries, 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 INNER
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, 'React Temp,' 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 only satisfied 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
value) interval 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
ignored) interval 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
ignored) interval 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 each
tag, and the remaining 16 rows will be bas ed on
subsequent value changes for any tag.
DELTA (any value is (no value) All values that changed during the specified time
ignored) interval 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 wwRes olution.
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 (t imestamp < cycle end).
If you want to use date/time functions and the wwTimeZone paramet er in the same query, you will
need to use the faaTZgetdate() function. This is because of differences in how the SQL Server and the
Wonderware Historian OLE DB provider determine the end date for a query.
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 Wonderware Historian OLE DB provider. The
Wonderware 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, expr essed 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 Pacific 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 EDT, 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 Wonderware 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.
To work around this problem, use the faaTZgetdate() function with intermediate variables. For
example:
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 OPE NQUERY function, you cannot perform arithmetic functions on the COUNT(*)
column. However, you can perform the count outside of the OPE NQUERY, 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 S UM 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 comparis on operators can be
used on the History and WideHistory tables. The comparison operators also apply regardless of how
the 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 dat e is returned, and the Quality value is 133 (because
the lengt h 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:01:00) does correspond exactly with an actual change in value, and is therefore
marked with the normal quality of 0.
The first row returned is the first valid change after (but not including) the start time (12:00:30):
The start time (12:01:00) corresponds exactly with an actual change in value, but it is excluded from
the result set becaus e 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.
Cyclic queries with the wwCycleCount time domain extension ret urn a set of evenly spaced 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 thes e 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)
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
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)
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 second resolution 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
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)
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 157
Example 2: Delt a and Full Retrieval on page 158
Example 3: Querying the WideHistory Table on page 159
Example 4: Querying the History Table wit h the wwValueSelector Parameter on page 160
Example 5: Calc ulating Total Time Bet ween Value Changes on page 161
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
Value
DateTime
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
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.
WHERE Pump1+Pump2=0
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:
Curs ors are a very powerful feature of SQL Server. They permit cont rolled movement through a record
set that results from a query.
For in-depth information on cursors, see your Micros oft SQL Server documentation.
The Wonderware Historian OLE DB Provider pr ovides server-side cursors. Cursors can be used to do
joins that are not possible in any other way. They can be used to join dat e/times from any source with
date/times in the history tables.
The following query provides an ex ample of using a server-side cursor. This query:
Fetches all of the events in the E ventHistory table.
Shows a "snapshot" of three tags at the time of each event.
Shows the event tag and its associated key value.
This query could easily be encapsulated int o a stored procedure. The query uses the four-part naming
convention.
Any normal SQL Server stored procedure can make use of the tables exposed by the Wonderware
Historian OLE DB Provider. Stored procedures can use any valid Transact -SQL syntax to access
Wonderware Historian historical data.
In other words, stored procedures can make use of four-part -queries, OPENQUERY and
OPENROWSET functions, cursors, parameterized queries and views. Stored proc edures can be used
to encapsulate complex joins and ot her operations for easy re -use by applications and end users.
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 ens ure 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 OPE NQUERY statement "on the fly" as a string,
and then execute it.
However, if the system was stopped between history blocks, there will be a gap in the data, as shown
in the following diagram:
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 generat ed 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 retrieved, an additional data point (A) will be insert ed by
retrieval to mark the end of the dat a. 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 ret rieval 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 Wonderware
Historian comput er. For delta retrieval, a single NULL value will be returned. For cyclic retrieval, a
NULL will be ret urned for each data value requested.
The following examples show how you can get the same data using these different met hods. All
examples use the SysTimeSec system tag, which has a range of 0 to 59.
Query 1
The following query uses the SQL Server average function to return the average value of the
SysTimeSec tag over the span of one minute.
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 94.
For example, consider the following query that ret urns process data values for the ’SysTimeMin’ tag:
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.
Wonderware Historian captures process 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 nam e 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 associ ated 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 E vents 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 REST/ OData interface.) 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 Wonderware Historian Database
Referenc e.
In This Chapter
Querying Alarms and E vents ....................................................................................................... 173
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]
00:00. 0 1 586277 6
00:00. 0 2 391149 5
00:00. 0 3 NULL 1
00:00. 0 1 152862 4
00:00. 0 2 19962 5
00:00. 0 3 NULL 1
00:00. 0 1 366367 4
00:00. 0 2 366370 2
… … … …
Area_001 6
UserDefined_001 6
-- ack time per severity per hour for high, medium and low
SELECT DATEADD(hour, DATEDIFF(hour, 0, e.EventTime), 0) as hour,
e.Severity,
avg(Alarm_UnAckDurationMs) as avg_unack,
count(*) as count
FROM Events e
WHERE
e.EventTime < @end
AND e.EventTime >= @start
AND e.Severity <=3 -- critical = 1, high = 2 medium = 3 low =
4
AND e.Type = 'Alarm.Acknowledged'
GROUP BY
DATEADD(hour, DATEDIFF(hour, 0, e.EventTime), 0),
severity
ORDER BY
DATEADD(hour, DATEDIFF(hour, 0, e.EventTime), 0),
e.severity
This query results in two reports. The first one looks like this:
00:00. 0 1 586277 6
00:00. 0 2 391149 5
00:00. 0 3 NULL 1
00:00. 0 1 152862 4
00:00. 0 2 19962 5
00:00. 0 3 NULL 1
00:00. 0 1 366367 4
00:00. 0 2 366370 2
… … … …
--======================--
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
Alarm Life -
B8A45440-3950-52F9-3040-0
0E8158D06BB - 22:40. 0 NULL 22:43. 0 NULL 3005
C HAPTER 5
Browser-Friendly Data Retrieval
In This Chapter
About Data Retrieval Using the iHistory Interface .......................................................................... 181
Querying the Historian Dat abas e ................................................................................................. 182
Using the Excel OData Feed to Import Process or E vent Dat a ....................................................... 186
Querying History Blocks via SQL S erver Reporting Services Extension .......................................... 188
Supported OData Retrieval Syntax .............................................................................................. 189
Resources .................................................................................................................................. 193
Summary Resources .................................................................................................................. 199
E vent Resources ........................................................................................................................ 206
Errors......................................................................................................................................... 211
A subset of the OData system query options is supported. For more information, see Supported
Syntax Tok ens and Operators on page 191.
Tip: For optimum viewing of the data returned by the OData interfac e, we rec ommend using the
JSONView viewer in the Chrome browser.
http://<host>:<port>/Historian/<ver>/$metadata
where:
o <host> and <port> specify the name and port used by the on -premises historian for Historian
InSight
o <ver> is the version number -- either " v1" or " v2".
For Wonderware Online InSight, type:
https://online.wonderware.com/apis/historian/7.8/$metadata
All date-times used in the iHistory web service are expressed in UTC. They all use the ISO 8601
format and the OData datetimeoffset data type.
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.
How you use date-time filters for process history, event data, and summary history varies:
Process hi story
For example, to filter based on a time range, you can include the following in your query:
…
DateTime+ge+datetimeoffset%272014-07-04T00:00:00.000Z%27+and+DateTime+le+
datetimeoffset%272014-07-04T12:00:00.000Z%27
…
The example above uses the DateTime property of the ProcessValues entity.
Event data
The E vent entity has a corresponding property called E vent Time that works similarly to DateTime
in the example above.
Summary history
By contrast, the Summary entity uses separat e StartDat eTime and EndDataTime properties. For
example:
…
StartDateTime+ge+datetimeoffset%272014-07-04T00:00:00.000Z%27+and+EndDate
Time+le+datetimeoffset%272014-07-04T12:00:00.000Z%27
…
Resolution Defines the resample interval (in milliseconds) to apply to the data. Applies to
Summaries and (depending on the mode) ProcessValues entities and the
Tag/Raw navigation property.
For example, to return hourly summaries for a day, set the start and end tim es to
report midnight to midnight, and the res olution to 3600000 (1 -hour).
The default resolution is 1 minut e.
RetrievalMode Cont rols the res ampling method to apply to the results. Applies to the
ProcessValues entity and the Tag/ Raw navigation property. Support ed values
include:
Cyclic
Delta
Full
Interpolated
BestFit (the default)
A verage
Min
Max
Integral
Slope
Counter
Runtime database (stored by the Classic Using SQL queries. For more information, see Edge
E vents subsystem) Detection for Events (wwE dgeDetection) on page 78.
A2ALMDB database Using SQL queries
Note: Earlier versions of Wonderware System Platform used WWALMDB dat abas e rather than
A2ALMDB for alarms and events. If you are currently using WWALMDB and want to to use A2ALMDB
instead, you may need to change your alarm historization settings from within the ArchestrA IDE and
change your alarm queries to use A2ALMDB.
http://Server1:32569/Historian/v1/Events?$filter=EventTime+ge+datetimeoff
set%27014-08-10T05:56:21.302Z%27
The following query returns events for the proc ess variable named Flow3.PV:
http://Server1:32569/Historian/v1/Events?$filter=Source_ProcessVariable+e
q
+%27Flow3.PV%27+and+EventTime+ge+datetimeoffset%272014-08-10T05:56:21.302
Z%27
The following query returns events for a source area called "Site2":
http://Server1:32569/Historian/v1/Events?$filter=Source_Area+eq+%27Site2%
27+and+EventTime+ge+datetimeoffset%272014-08-10T05:56:21.302Z%27
The following query returns alarms that have returned to normal:
http://Server1:32569/Historian/v1/Events?$filter=Type+eq+%27Alarm.Clear%2
7
The following query returns alarms that have returned to normal and uses the $select option to ret urn
only a subset of the properties:
http://Server1:32569/Historian/v1/Events?$select=EventTime,Source_Area,So
urce_ProcessVariable,Comment&$filter=Type+eq+%27Alarm.Clear%27
The following query returns all events with an event time t hat is greater than or equal to the specified
time:
http://Server1:32569/Historian/v1/Events?$filter=EventTime+ge+datetimeoff
set%271970-01-01T00:00:00.000Z%27
The following query returns the first 10 events:
http://Server1:32569/Historian/v1/Events?$top=10&$filter=EventTime+ge+dat
etimeoffset%271970-01-01T00:00:00.000Z%27
The following query skips the first 10 events:
http://Server1:32569/Historian/v1/Events?$skip=10&$filter=EventTime+ge+da
tetimeoffset%271970-01-01T00:00:00.000Z%27
Analog Several of the values return selected, stored values rather than actual statistics.
These have associated timestamps (First, Last, Minimum, Maximum). The
actual statistics are all time-weighted.
Split or Contained The Split and Contained arrays include statistics on the amount of time (in
milliseconds) that the value spent in each state that occurred in the period.
Each array includes an element for each value encountered during that period.
If the value was "1" for the entire period queried, there is only one element; if
the value was "0", "1", and "2" in another period, the results for that period has
three rows.
For each array element, the statistics represent the amount of time the value
was in that state. For example, if you query an hour of data and the value was
"3" four times during that hour, for a total of 10 minutes, then the "A verage"
would be 150,000 milliseconds (2.5 minutes).
3. In the Location of the data feed section, enter the link for the OData Feed. Append the location
with the query option $format with a value of atom.
For example, you could append an on-premises location like this:
//localhost:32569/Historian/v2/Events?$format=atom
Note: To make the link more usable, you would also include a Date Time filter (see "Using Date
Time Filters" on page 182).
4. For Log on credentials, select the appropriate logon option and type the correct username and
password. The logon is valid until the Excel spreadsheet is closed.
6. Select the appropriat e table. For events data, select the Events table.
7. Click Next. The Save Data Connection File and Finish dialog box appears.
10. In the Select how you want to view this data in your workbook area, click Table.
11. In the Where do you want to put the data? area, specify if data goes to an existing or a new
worksheet.
12. Click OK. A static result set appears in the worksheet.
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 JSONView viewer in the Chrome browser, you can us e a plus sign (+) to
indicate a space to mak e 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
<protocol>://<host>:<port>/<service_name>/7.8/<path>/<options>
Note: For process value and summary retrieval queries, the fully qualified
name is a mandatory filter value. The request will not work without it.
The default URLs for retrieving data through the OData interface are as follows:
http://<host>:<port>/Historian/v2/ProcessValues
For event data:
http://<host>:<port>/Historian/v2/Events
Examples
This query lists all resources available for query on the server:
http://server1:32569/Historian/v1/$metadata
This query gets all events after August 1, 2016 at 6:15 p.m.:
http://server1:32569/Historian/v1/Events?$filter=EventTime+ge+2016-08-01T
18:15:00.000000Z
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.
Each time you retrieve records, a maximum of 5,000 records is returned. For event ret rieval, only the
first 50 records for your query are returned by default. At the end of the last record, there is a link to the
next record set.
If you do not specify a time criteria in the query, then the last hour’s worth of data is returned by
default. If you specify time in your queries, use UTC. Fo r example:
2016-08-01T18:15:00.000000Z
If you use local time, be aware of UTC offset values in timezones that observe Daylight Savings Time.
For example, the following time specification would mean a 5-hour offset from UTC:
2014-07-4T23:00:0.000-5:00
However, the offset for time specification would need to be adjusted if Daylight Savings Time is in
effect:
2014-07-4T23:00:0.000-6:00
Records are always returned in UTC, regardless of any time offset included in the query.
http://server1:32569/Historian/v2/$metadata
Returns:
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 returned in the query results
reflects the case of the stored value.
$skip Specifies the number of records to skip from the beginning of the res ult set.
$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 only have a single time clause combined with a single filter clause
using the "and" operat or. The filter claus e itself can be complex, using any of the supported logical
operators. Use parentheses ( ) to creat e precedence groups within an expression in filter clause.
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" operator. For example:
...
((Priority+eq+100+or+Priority+eq+200+or+Priority+eq+500+or+Priority+eq+70
0)+and+(filter …))
When the filter clause is specified with E ventTime, where E vent Time Great erThan (or) GreaterThan
Equal, the E vent Time will be considered as the Start Time. E vent Time LessThan (or) Less ThanEqual
will be considered as EndTime. After considering the Start Time and EndTime, if any filter exists that
will be considered as First Filter, and there is no value if we specify OR (or) AND FilterOption for the
First Filter apart from the Start Time and EndTime.
The following queries both return the same res ult as using " and":
http://localhost:32569/Historian/v1/Events?$filter=EventTime+gt+datetimeo
ffset%272014-07-20T02:26:45%27+or+Priority+lt+900
http://localhost:32569/Historian/v1/Events?$filter=EventTime+gt+datetimeo
ffset%272014-07-20T02:26:45%27+and+Priority+lt+900
Resources
Historian Dat a RES T API 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:
Tags (see "Tags" on page 194)
TagProperties (see "TagProperties" on page 195)
TagPropertyV alues (see "TagP ropert yValues" on page 195)
TagGroups (see "TagGroups" on page 195)
TagSuggest (see "TagSuggest " on page 196)
TagSearch (see "TagS earch " on page 196)
TagE xtendedP roperties (see "TagE xtendedProperties" on page 197)
ProcessValues (see "ProcessValues" on page 198)
Daily (see "Daily" on page 199)
Hourly (see "Hourly" on page 205)
Minutely (see " Minutely" on page 206)
SystemParameter (see "SystemP arameters" on page 198)
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."
Tags
The Tags resource retrieves tag metadata. For version 2, this also includes tag extended properties.
FNQ* String The fully qualified name for the tag. A fully qualified tagname
uses the format: Dat aSourceName. TagName.
Source String The data source.
EngUnit String The engineering units used for the tag's rec orded values.
MessageOff String The message associated with the FALSE state of the discrete
tag. The maximum number of characters is 64. A discrete tag
set to 0 is in the FALSE state.
MessageOn String The message associated with the TRUE state of the discrete
tag. The maximum number of characters is 64. A discrete tag
set to 1 is in the TRUE state.
TagName String The unique name of the tag wit hin the Wonderware Historian
system.
* Required property.
TagProperties
The TagProperties resource lists all properties used in the system. Tag properties include both base
and extended properties of a tag.
Examples of TagProperties are DataSourceName and Unit.
* Required property.
TagPropertyValues
The TagPropertyValues res ource retrieves values for one or more tag properties. Tag properties
include base and extended properties of Tag. Examples of TagProperties are DataS ourceName and
Unit.
Value* String
* Required property.
TagGroups
The TagGroup resource retrieves information about data sources. Each dat a source contains a group
of tags.
ParentID String
Scope String Used for tag-level security, this defines a location within the
data source.
Tags Identifies related Tags.
* Required property.
TagSuggest
The TagSuggest resource provides search suggestions in response to user input. The data ret urned by
this entity depends on the historian’s implementation of searc h functionality. Some historians will return
empty result sets.
It finds all the matching results for a given query string. It searches for the matching rec ord based on all
the searchable fields in the search index; such as, source, tagname, description, and engineering unit.
The results contain the matching field name, value, hit count, and search ranking.
The query option "q" specifies the query string (for example, the value typed by the user int o the
search box).
For example:
http://localhost/Historian/v2/TagSuggest?q=r&$top=100
Search
ExpandS uggest
* Required property.
TagSearch
The TagSearch resourc e provides tagname results based on provided searc h paramet ers.
The data returned by this entity is dependent on the historian’s implementation of search functionality.
Some historians will ret urn 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.
For example:
http://localhost/Historian/v2/TagSearch?q=r&kn=source&kv=atron
FQN* String The fully qualified name for the tag. A fully qualified tagname
uses the format: Dat aSourceName. TagName.
Source String The data source.
Tag Returns a URL to retrieve a list of Tag entity values for the
tags that match.
* Required property.
TagExtendedProperties
The TagExtendedProperties res ource represents all the Tag properties, including both standard and
extended properties.
FQN* String The fully qualified name for the tag. A fully qualified tagname
uses the format: Dat aSourceName. TagName.
PropertyName* String The name of the property.
ProcessValues
The Proc essValues resource retrieves a set of process history values.
FQN* String The fully qualified name for the tag. A fully qualified tagname
uses the format: Dat aSourceName. TagName.
DateTime* DateTimeOffset DateTime (Edm. DateTimeOffset) is always specified in UTC
using the RFC3339 / ISO8601 format with the Z time zone
designator. For example: 2016-09-03T18: 44:09.352247Z
OPCQuality Int32 The data quality as reported by the source.
Value Double 0 or 1 .
Text String Cont ain the value for a string tag or message associated with
Discrete Tags, while Value will contain 0 or 1.
* Required property
SystemParameters
(On-premises Wonderware Historian InSight only)
The SystemParameters resource retrieves names and values for system parameters.
* Required property.
Summary Resources
The Summary history data dictionary includes these structures:
DailySummary (see "Daily" on page 199)
HourlySummary (see "Hourly" on page 205)
MinutelySummary (see " Minutely" on page 206)
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."
Summary Structure
The Summary structure represent summary data with a user-defined interval.
The additional query option "Res olution" is used to specify the interval to be used for this entity.
The earliest and latest requested values of StartDateTime and/or EndDateTime are used for
determining the span of time covered by the summary intervals returned.
PercentGood Double
Analog Analog
Statistics
Split Collection
(State
Statistics)
Cont ained Collection
(State
Statistics)
Raw
* Required property.
Daily
The Daily resource retrieves daily (24-hour resolution) summary values for the tags specified. The
default for Daily is to report summary values for the last week.
FQN* String The fully qualified name for the tag. A fully qualified tagname
uses the format: Dat aSourceName. TagName.
StartDateTime* DateTime Start of the timeframe reported.
Offset
EndDateTime* DateTime End of the timeframe reported.
Offset
TimeZone String The timezone used for the timeframe. See "Accepted values
for TimeZone" below.
OPCQuality Double OPC quality. Normal OPC quality retrieval logic is applied if:
All the point found and processed for this row have GOOD
quality. If they all have the same GOOD quality, then that
quality is returned.
If there is a gap in the entire calculation cycle, then BAD
quality is returned for the tag.
For any other scenario with any mixture of GOOD and BAD
points, a DOUB TFUL OP C quality (64) is returned.
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.
Analog Analog An embedded collection that maps to AnalogSummary.
Statistics
Split Collection An embedded collection that maps to StateSummary for the
(State ValueState retrieval mode.
Statistics)
Cont ained Collection An embedded collection that maps to StateSummary for the
(State Cont ainedState retrieval mode.
Statistics)
Raw A URL us ed to retrieve all stored values for a specified time
period and tag. This is equivalent to a preconfigured
ProcessValue (s ee "ProcessValues" on page 198) query.
Minute
Hourly
* Required property.
Accepted values for TimeZone
0 UTC
720 UTC+ 12
-120 UTC-02
-480 UTC-08
-540 UTC-09
-660 UTC-11
Hourly
The Hourly resource ret rieves hourly summary values for the tags specified. The default for Hourly is to
report summary values for the last 24 hours.
FQN* String The fully qualified name for the tag. A fully qualified tagname
uses the format: Dat aSourceName. TagName.
StartDateTime* DateTime Start of the timeframe reported.
Offset
EndDateTime* DateTime End of the timeframe reported.
Offset
OPCQuality Double OPC quality. Normal OPC quality retrieval logic is applied if:
All the point found and processed for this row have GOOD
quality. If they all have the same GOOD quality, then that
quality is returned.
If there is a gap in the entire calculation cycle, then BAD
quality is returned for the tag.
For any other scenario with any mixture of GOOD and BAD
points, a DOUB TFUL OP C quality (64) is returned.
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.
Analog Analog An embedded collection that maps to AnalogSummary.
Statistics
Split Collection An embedded collection that maps to StateSummary for the
(State ValueState retrieval mode.
Statistics)
Cont ained Collection An embedded collection that maps to StateSummary for the
(State Cont ainedState retrieval mode.
Statistics)
Raw A URL us ed to retrieve all stored values for a specified time
period and tag. This is equivalent to a preconfigured
ProcessValue (s ee "ProcessValues" on page 198) query.
Minute
* Required property.
Minutely
The Minutely resource retrieves summary values with a 1 -minute resolution for the tags specified.
Default duration for minutely summaries is the last 1 hour. The default for Minut ely is to report
summary values for the last hour.
FQN* String The fully qualified name for the tag. A fully qualified tagname
uses the format: Dat aSourceName. TagName.
StartDateTime* DateTime Start of the timeframe reported.
Offset
EndDateTime* DateTime End of the timeframe reported.
Offset
OPCQuality Double OPC quality. Normal OPC quality retrieval logic is applied if:
All the point found and processed for this row have GOOD
quality. If they all have the same GOOD quality, then that
quality is returned.
If there is a gap in the entire calculation cycle, then BAD
quality is returned for the tag.
For any other scenario with any mixture of GOOD and BAD
points, a DOUB TFUL OP C quality (64) is returned.
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.
Analog Analog An embedded collection that maps to AnalogSummary.
Statistics
Split Collection An embedded collection that maps to StateSummary for the
(State ValueState retrieval mode.
Statistics)
Cont ained Collection An embedded collection that maps to StateSummary for the
(State Cont ainedState retrieval mode.
Statistics)
Raw A URL us ed to retrieve all stored values for a specified time
period and tag. This is equivalent to a preconfigured
ProcessValue (s ee "ProcessValues" on page 198) query.
* Required property.
Event Resources
The Historian Data REST AP I includes the following resources for retrieving data:
Event Data Structure on page 207
Provider Dat a Structure on page 207
User Data Structure on page 208
Source Data Structure on page 208
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."
Priority Int32 Value indicating the import ance of the event. Values range
from 1 to 999, with lower numbers indicating higher
importance.
E vent Time DateTime UTC timestamp indicating when the event occurred.
ReceivedTime DateTime UTC timestamp indicating when the event was received by
the Historian server.
InTouchType String InTouch Type value. Examples include "ALM", "RTN", "ACK",
and "SYS", among ot hers.
* Required property.
Data
Property Name Type Description
Data
Property Name Type Description
User_Account String This is the login name for the operator for the given application.
User_NodeName String Computer name from which a user action was executed.
User_Agent String Application name that the user was running when the event was
generated.
Data
Property Name Type Description
Source_Object String Non-hierarchical name for the object to which the event
is related, for example, " TIC101".
Data
Property Name Type Description
Source_HierarchicalObject String Hierarchical name for the source object. For example,
"Reactor_001. TIC".
Data
Property Name Type Description
Alarm_ID String ID of the original Alarm event. For "Alarm.Set" events, this
will be the same as the event ID.
Alarm_InAlarm Boolean "true" or "false" indicating whether the Alarm is still in the
active state.
Alarm_State String State of the alarm. Possible values are "UNA CK_ALM",
"UNA CK_RTN", "ACK_ALM", and "ACK_RTN".
ValueString String Value logged for the variable related to the event.
Data
Property Name Type Description
Alarm_UnAckDurationMs Int32 The duration, in milliseconds, for which the alarm went
un-acknowledged.
Alarm_DurationMs Int32 The duration, in milliseconds, for which the alarm was
active.
Alarm_IsSilenced Boolean "true" or "false" indicating whether the alarm was silenced.
Alarm_IsShelved Boolean "true" or "false" indicating whether the alarm was shelved.
Alarm_S helveStartTime Date Scheduled start of the shelve time if the alarm has been
Time shelved.
Alarm_S helveDurationMs Int32 The duration, in milliseconds, for which the alarm was
shelved.
Alarm_OriginationTime Date Provides the time of the initial alarm condition, so that it can
Time be ret rieved quickly.
Verifier_Account String The login name for the verifier of a verified write operation.
Verifier_Name String First and last name of the verifier of a verified write operation.
Verifier_NodeName String Computer name from which a user write was verified.
Verifier_Agent String Name of the application the verifier of a user write was running.
Flexible Properties
If an event is generated with a property that is not handled by the defined dat a dictionary, then that
property is considered a flexible property. These flexible properties appear in the result set with a
property name of "Properties."
The following are JSON examples of an event with flexible properties, which are named "property1"
and "property2".
{
"odata.metadata":"http://localhost:32569/Historian/$metadata#Events","value":[
{
"Comment":"DisplayText","EventTime":"2014-09-02T16:03:12Z","ID":"1d9b9518-
b1ca-4270-a189-e43cc258645f","Priority":708,"ReceivedTime":"0001-01-01T00:
00:00Z","IsAlarm":false,"Severity":3,"Type":"EventType1","Provider_NodeNam
e":"RM00155948","Provider_System":"System1","Source_ProcessVariable":"Sour
ce1","Source_Area":"Area1","Alarm_IsSilenced":false,"Properties":[
{
"Name":"property1","Value":"QZIKFGN"
},{
"Name":"property2","Value":"8982922"
}
]
},{
"Comment":"DisplayText","EventTime":"2014-09-03T01:16:22Z","ID":"2aae8e30-
72ae-4839-b7ff-c1a2ec7f4cc5","Priority":566,"ReceivedTime":"0001-01-01T00:
00:00Z","IsAlarm":true,"Severity":2,"Type":"EventType1","Provider_NodeName
":"RM00155948","Provider_System":"System1","Source_ProcessVariable":"Sourc
e1","Source_Area":"Area1","Alarm_ID":"a4a8bb5c-cc96-4bdd-b266-81a566c4c4bc
","Alarm_Class":"ALMC","Alarm_Type":"ALMTYP","Alarm_IsSilenced":false,"Ala
rm_State":"ALMSTATE","Properties":[
{
"Name":"property1","Value":"IRFMOGF"
},{
"Name":"property2","Value":"5105479"
}
]
},{
"Comment":"DisplayText","EventTime":"2014-09-03T04:09:16Z","ID":"4047bb01-
dc4b-4b25-99e0-399d2c6a38af","Priority":785,"ReceivedTime":"0001-01-01T00:
00:00Z","IsAlarm":false,"Severity":2,"Type":"EventType1","Provider_NodeNam
e":"RM00155948","Provider_System":"System1","Source_ProcessVariable":"Sour
ce1","Source_Area":"Area1","Alarm_IsSilenced":false,"Properties":[
{
"Name":"property1","Value":"DBDPGDV"
},{
"Name":"property2","Value":"7680935"
}
]
}
],"odata.nextLink":"http://localhost:32569/Historian/Events?$top=3&$filter=Event
Time%20ge%20datetimeoffset%272014-09-01T16%3A28%3A20.0000000Z%27%20and%20%27prop
erty1%27%20ne%20%270%27&$skiptoken=2014-09-03T04:09:16.0000000Z%7C4047bb01-dc4b-
4b25-99e0-399d2c6a38af"
}
Errors
The OData error codes listed in the following table may be returned by an operation on any of the
storage services.
InvalidQueryParameterValue Bad Request (400) An invalid value was specified for one
of the query paramet ers in the
request URI.
RequestUrlFailedToParse Bad Request (400) The url in the request could not be
parsed.
InvalidHttpVerb Bad Request (400) The HTTP verb specified was not
recognized by the server.
InvalidInput Bad Request (400) One of the request inputs is not valid.
ResourceNotFound Not Found (404) The specified resource does not exist.