This Script reads the last value for all 600 Analog Tags from the DataLog Access Database on the Project Node :
# Get Last Value for 600 Analog Tags from Data Log to ODBC
# SETVAL to last value recorded in DataLog
# Important to turn Action Log off to make
#script run faster - else each SETVAL
# will require a write to the Action Log text file
#and possibly ODBC
SETVAL %DALOGSTATUS=0
# bwPDATAaccess is an ODBC DSN attached to an Access Database on Project Node
SQLDIRECT "CONNECT SESSION 3 TO bwpdata_ACCESS"
SQLDIRECT "USE SESSION 3"
# DECLARE A POINTER TO NEWEST DATA JUST ENTERED
#SQLPREPARE "SELECT TagName, LogDate, LogTime, LastValue "
SQLPREPARE "DECLARE C3 CURSOR FOR "
SQLPREPARE "SELECT DISTINCT TagName, LogDate, LogTime, LastValue "
SQLPREPARE "FROM bwAnalogTable "
SQLPREPARE "ORDER BY LogDate DESC, LogTime DESC"
SQLEXECUTE
SQLDIRECT "OPEN C3"
#This does the Work
# Text1, text2, text3, text4 are Text-type Constant Tags
# that act as temporary holders
# SQL commands return to Tags only (not variables)
# Loops thru
for {set Z 5} {$Z<=16} {incr Z} {
SQLDIRECT "FETCH NEXT C3 INTO text1, text2, text3, text4"
set tagnm [GETVAL text1]
set lastval [format %4.2f [GETVAL text4]]
SETVAL $tagnm=$lastval
}
SQLDIRECT "CLOSE C3"
SQLDIRECT "DISCONNECT SESSION 3"
SETVAL %DALOGSTATUS=1