ReadBeforeSQL

ReadBeforeSQL can accept the following arguments in the string:

Argument Data Type Description
?TagId varchar(1000) If called from the Administrator, contains the search string entered by the user. If called from a service, contains the tag configured in the variable sheet or model.
?Timestamp datetime Timestamp from which to query from.
?NumValues int The number of values to be returned.
?IncludeExactTime int An option that specifies whether to return a data point that is equal to the timestamp (for example, data points >= ?TimeStamp), as opposed to data that is only greater than the timestamp.
?HonorRejects int -

ReadBeforeSQL must return data in the following format:

Order Field Data Type Description
1 Timestamp datetime Timestamp of the data point.
2 Value Value of the data point.
3 Status varchar(10) Quality of the data point and has to be one of two values, ‘Good’ or ‘Bad’.

An example stored procedure for the ReadBeforeSQL is as follows:


CREATE PROCEDURE dbo.spServer_HistorianReadBefore 
@TagId	varchar(1000),
@Timestamp	datetime,
@NumValues	int,
@IncludeExact	int,
@HonorRejects	int AS
SET ROWCOUNT @NumValues 
SELECT	TimeStamp,
      Value, 
      ‘Good’
 
FROM MyHistorianTable 
WHERE	Tag_Id = @TagId
     AND (	TimeStamp < @Timestamp
             OR (		TimeStamp = @Timestamp AND @IncludeExact = 1))
ORDER BY TimeStamp ASC