README for the HP Neoview Command Interface (NCI) (Upd1 R2.3 SP2)
Syntax:
IF { condition } THEN { action } { SQLTERMINATOR }
The condition parameter is a Boolean statement structured as follows:
condition
{ variable-name | value } { operator } { variable-name | value }
variable-name
{ LASTERROR | RECCOUNT | ACTIVITYCOUNT | ERRORCODE |
[%] any ENV variable | any SQL parameter }
value
{ any-integer | quoted-string }
quoted-string
“any non-quote character” [\] is the optional escape character
operator
The following is a list of valid operators and their meanings
== | = equal to
<> | != | ~= | ^= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
The action parameter is any NCI or SQL Command
action
{SQL Command | Neoview Script Command}
IF…THEN is itself an <action> thus nested IF…THEN statements are allowed. action must end
in the SQL terminator, even if the action is an interface command.
Example:
SQL> INVOKE Employees
SQL> -- ERROR 4082 means the table does not exist
SQL> IF ERRORCODE != 4082 THEN GOTO BeginPrepare
SQL> CREATE TABLE Employees(SSN INT PRIMARY KEY NOT NULL NOT DROPPABLE, FName VARCHAR(50),
LName VARCHAR(50), HireDate DATE DEFAULT CURRENT_DATE);
SQL> LABEL BeginPrepare
SQL> PREPARE empSelect FROM
+> SELECT * FROM
+> Employees
+> WHERE SSN=?empSSN;
SQL> IF USER == “alice” THEN SET PARAM ?empSSN 987654321;
SQL> IF %USER == “bob” THEN SET PARAM ?empSSN 123456789;
SQL> execute empSelect
SQL> IF USER == “alice” THEN
+> IF ACTIVITYCOUNT == 0 THEN GOTO insertAlice;
SQL> IF USER == “bob” THEN IF ACTIVITYCOUNT == 0 THEN GOTO insertBob;
SQL> EXIT
SQL> LABEL insertAlice
SQL> INSERT INTO Employees(SSN, FName, LName) VALUES(987654321, 'Alice', 'Smith');
SQL> EXIT
22