Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Historian

InTouch example: retrieving data from the grid

  • Last UpdatedFeb 05, 2025
  • 1 minute read

The following example script demonstrates how to extract data from the grid using the ColumnValue method.

#aaHistClientActiveDataGrid.ServerName = "maggie";

#aaHistClientActiveDataGrid.UserName = "wwUser";

#aaHistClientActiveDataGrid.Password = "wwUser";

#aaHistClientActiveDataGrid.DatabaseName = "Runtime";

#aaHistClientActiveDataGrid.SQLString = "";

#aaHistClientActiveDataGrid.SQLAppend("DECLARE @StartDate Datetime");

#aaHistClientActiveDataGrid.SQLAppend("DECLARE @EndDate Datetime");

#aaHistClientActiveDataGrid.SQLAppend("SELECT @StartDate = DateAdd(mi, -30, GetDate())");

#aaHistClientActiveDataGrid.SQLAppend("SELECT @EndDate = GetDate()");

#aaHistClientActiveDataGrid.SQLAppend("SELECT TagName, DateTime, Value");

#aaHistClientActiveDataGrid.SQLAppend("FROM v_AnalogHistory");

#aaHistClientActiveDataGrid.SQLAppend("WHERE TagName IN ('SysTimeSec')");

#aaHistClientActiveDataGrid.SQLAppend("AND DateTime >= @StartDate");

#aaHistClientActiveDataGrid.SQLAppend("AND DateTime <= @EndDate");

#aaHistClientActiveDataGrid.SQLAppend("AND wwRetrievalMode = 'Cyclic'");

#aaHistClientActiveDataGrid.SQLAppend("AND wwCycleCount = 100");

#aaHistClientActiveDataGrid.Connected = 1;

#aaHistClientActiveDataGrid.MoveFirst();

FOR Row = 1 TO #aaHistClientActiveDataGrid.RowCount

TagName = #aaHistClientActiveDataGrid.ColumnValue(0);

DateTime = #aaHistClientActiveDataGrid.ColumnValue(1);

TagValueText = #aaHistClientActiveDataGrid.ColumnValue(2);

TagValue = StringToReal( TagValueText );

EndOfFile = #aaHistClientActiveDataGrid.EOF;

IF EndOfFile THEN

EXIT FOR;

ELSE

#aaHistClientActiveDataGrid.MoveNext();

ENDIF;

NEXT;

Another slightly different approach is to go through the returned data without actually moving the row selector using the RowColumnValue method. This approach is much more efficient because there is no UI updating.

#aaHistClientActiveDataGrid.ServerName = "maggie";

#aaHistClientActiveDataGrid.UserName = "wwUser";

#aaHistClientActiveDataGrid.Password = "wwUser";

#aaHistClientActiveDataGrid.DatabaseName = "Runtime";

#aaHistClientActiveDataGrid.SQLString = "";

#aaHistClientActiveDataGrid.SQLAppend("DECLARE @StartDate Datetime");

#aaHistClientActiveDataGrid.SQLAppend("DECLARE @EndDate Datetime");

#aaHistClientActiveDataGrid.SQLAppend("SELECT @StartDate = DateAdd(mi, -30, GetDate())");

#aaHistClientActiveDataGrid.SQLAppend("SELECT @EndDate = GetDate()");

#aaHistClientActiveDataGrid.SQLAppend("SELECT TagName, DateTime, Value");

#aaHistClientActiveDataGrid.SQLAppend("FROM v_AnalogHistory");

#aaHistClientActiveDataGrid.SQLAppend("WHERE TagName IN ('SysTimeSec')");

#aaHistClientActiveDataGrid.SQLAppend("AND DateTime >= @StartDate");

#aaHistClientActiveDataGrid.SQLAppend("AND DateTime <= @EndDate");

#aaHistClientActiveDataGrid.SQLAppend("AND wwRetrievalMode = 'Cyclic'");

#aaHistClientActiveDataGrid.SQLAppend("AND wwCycleCount = 100");

#aaHistClientActiveDataGrid.Connected = 1;

FOR Row = 1 TO #aaHistClientActiveDataGrid.RowCount - 1

TagName = #aaHistClientActiveDataGrid.RowColumnValue(Row, 0);

DateTime = #aaHistClientActiveDataGrid.RowColumnValue(Row, 1);

TagValueText = #aaHistClientActiveDataGrid.RowColumnValue(Row, 2);

TagValue = StringToReal ( TagValueText );

NEXT;

TitleResults for “How to create a CRG?”Also Available in