Using Tokens

SQL Tag Templates use tokens to dynamically replace text in a script with values retrieved from PARCview, like the start and end times of a trend or a tag id, just prior to the execution of the query. Tokens are delimited in the query text with the following syntax: {token}

Text Box: SELECT SampleTime, MeasuredValue
FROM labmeasurement
WHERE test = '{TagId}' AND SampleTime BETWEEN '{StartTime}' AND '{EndTime}' ORDER BY SampleTime

In this example {TagId}, {StartTime} and {EndTime} are text substitution tokens, which will be replaced with arguments supplied by PARCview at runtime.

Available Tokens

 

Location

This value is supplied by the Location portion of the UTag whose data is being retrieved, e.g. Location.Source.TagID/TagSwitch

Source

This value is supplied by the Source portion of the UTag whose data is being retrieved, e.g. Location.Source.TagID/TagSwitch

TagId

This value is supplied by the Tag Id portion of the UTag whose data is being retrieved, e.g. Location.Source.TagID/TagSwitch

StartTime

The start time of a tag data request

StartDate

Same as StartTime

EndTime

The end time of a tag data request

EndDate

Same as EndTime

UserID*

The value in the UserID field in this source’s configuration.

Password*

The value in the Password field in this source’s configuration.

LimitType

A numeric value used by the Limit script corresponding to the type of limit being requested, returns: 1 = Control, 2 = Spec, 3 = Operator

BasisTime

Start datetime of the grade specified in BasisValue

BasisValue

The value that specifies for which grade to retrieve limits

AggregateType

Which aggregate to calculate, retrieved from tag switch

StepInterval

Aggregate step interval in seconds, retrieved from tag switch

Resolution

Current plot resolution, set by the trend

ProjTime

Projection start time, uses Now time in trend

DataType

Data type as returned by Tag Info query

BoundsOn

Shows whether Include Bounds is True (1) or False (0)

TimeStamp

Used by PARCview to specify the timestamp of a single value in the Insert, Update and Delete scripts

WriteValue

Used by PARCview to specify a value in the Insert and Update scripts

WriteQuality

Used by PARCview to specify quality in the Insert and Update scripts

 

*If a source does not require a user name or password for making a connection, the UserID and Password tokens can be used to configure multiple sources to use the same SQL Tag Templates, differing only in one or two parameter values. For example, the structure of the queries between sources might be nearly identical except that they access different tables names, which could be supplied in the User Name and Password fields in the source’s configuration.

 

Using Logic with Tokens

Simple logic can be used with tokens to build if/then/else statements and to replace null values with a default value.

If/Then/Else syntax:

Text Box: {if: '{TagId}' = 'Value1' OR '{TagId}' = 'Value2' then: 'True text' else" 'False text'}

Notes: The text in the “then:” and “else:” statements can contain tokens. Nesting of tokens is not supported. The text in the “if:” statement cannot contain quotation marks.

IsNull/Replace syntax:

Text Box: SELECT SampleTime, MeasuredValue
FROM labmeasurement
WHERE test = '{TagId}' AND SampleTime BETWEEN '{StartTime}' AND {IsNull EndTime Replace: "getdate()"} ORDER BY SampleTime

Custom Tokens

User-defined tokens can be used in the tag list script (see below). Custom tokens are any that PARCview finds in the script that are not one of the predefined tokens. The values that replace these tokens are supplied by the attributes of a UTag, specified in a tag switch:

Location.Source.TagName/TagSwitch