int SQLSelect(DWORD id, string Table, string BindList, string whereExpr, string orderExpr);
It is a function that imports the connected database data into the virtual memory of the SCADA Server.
After executing this function, you can retrieve the record using functions such as SQLFirst, SQLGetPos, SQLLast, SQLNext, SQLPrev, and SQLSetPos.
Parameters
id - Access number connected by SQLConnect
Table - The name of the table in the database you want to import (MS-SQL can also be a VIEW table)
BindList - The name of the list of connection settings set in the editor
whereExpr - Only records that meet this condition are imported. IF YOU SET IT TO "VALUE > 10", ONLY RECORDS WITH A VALUE FIELD GREATER THAN 10 WILL BE IMPORTED INTO MEMORY. (Each ODBC engine may interpret this slightly differently when the SQL statement is executed, so refer to the WHERE help for each database program.)
orderExpr - When you import data, you can set a sort order. IF YOU SET IT TO "NAME" OR "NAME ASC", IT WILL BE SORTED IN ASCENDING ORDER BY THE NAME FIELD AND IMPORTED INTO MEMORY. If you set it to "NAME DESC", it will be sorted in descending order. (Note: Up to version 5.13, you should always write the letter BY in front of "BY NAME", and in versions after 5.14, you should omit BY as in "NAME".) This section may be interpreted slightly differently by each ODBC engine when SQL statements are executed, so refer to the ORDER BY help for each database program.
return °ª
A return value of 0 means that the function was not successful.
Example1
@SQLSelect(id, "ValueTable", "BindListValue", "", "");
@SQLFirst(id);
Description : It reads all the records from the ValueTable table in the
database and puts them in virtual memory.
When you run the following
sentence, SQLFirst, it will transfer the data from the first recorded recorded
to the tag you set in BindListValue.
Example2
@SQLSelect(id, "ValueTable", "BindListValue", "VALUE < 0", "");
@SQLLast(id);
Description : It reads only records from the ValueTable table in the database
with a VALUE field less than 0 and puts them in virtual memory.
When you run
the next sentence, SQLLast, it will transfer the last recorded record read to
the tag you set in BindListValue.
Example3
@SQLSelect(id, "ValueTable", "BindListValue", "", "NAME DESC");
@SQLLast(id);
Description : It reads all the records from the ValueTable table in the
database, sorted in descending order with the NAME field, and puts them in
virtual memory.
When you run the next sentence, SQLLast, it will transfer the
last recorded record read to the tag you set in BindListValue.
Related Helps