The SELECT command retrieves data from the relational database based on the selection criteria.
SQT1 – in this example, the SQL Trigger block uses the following SELECT command defined in the SQLLIB table:
Select COL1, COL2 from TBL1 where COL3=?;
SQD1 – in this example, the SQL Data block references three tag and field name combinations in the database, and sets the direction for two of them to IN and the other to OUT.
T01-. AI1.A_DESC
T02-. AO1.F_CV
T03-. DO1.A_ADI
TBL1 — is the table referenced by the SELECT command used by the SQT block.
COL1 |
COL2 |
COL3 |
Pump stage 101 |
99.7 |
NONE |
Temp Zone 2 (C) |
-2.1 |
ByeBye |
Manual Override |
.004 |
NONE |
Deadband |
9 |
ALL |
Explanation
When the software executes this command, the value for DO1.A_ADI is read, since it is an outgoing field. The value for the field is ALL. This command retrieves only the last row since it is the only row that matches the selected criteria. The values from COL1 and COL2 in the last row are selected from TBL1 and are written to AI1.A_DESC and AO1.A_CV.
The new descriptor for AI1 is now Deadband. The new current value for AO1 is now 9.
The process database does not accept null values. If the SQL task reads a null value from the SQL table, no value is written to the target database block field. Additionally, the SQT block generates an alarm and a field write error. However, any other non-null values selected are written to the process database.