Parameters

Advantage SQL Engine

Using parameters in an SQL script is only supported when the parameters are used in regular SQL DDL or DML statements. They are not supported in other expressions or script statements, such as the IF, WHILE, or RAISE statements. This limitation may be eliminated in a future release but a workaround to this restriction is suggested below:

Example 1: Supported usage of parameter in script

DECLARE i Integer;

i = ( SELECT id FROM #input );

IF i = 1 THEN

INSERT INTO table1 Values( :val1, :val2 );

ELSE

UPDATE table1 SET name = :val3 WHERE id = :val4;

END;

 

The example takes 4 parameters and executes either an INSERT statement using the first two parameters or executes an UPDATE statement using the last two parameters.

Example 2: Unsupported usage of a parameter in a script

DECLARE strName String;

strName = (SELECT name FROM table1 WHERE id = :id );

 

The example above is trying to use a parameter in an assignment statement to retrieve a string value from a table based on the value of the parameter. However, parameters are currently not supported in assignment statements. The next example shows how to work around the restriction.

Example 3: Getting parameter value in the variables

DECLARE strName String;

CREATE TABLE #temp ( name memo );

TRY

INSERT INTO #temp SELECT name FROM table1 WHERE id = :id;

StrName = (SELECT name FROM #temp);

FINALLY

DROP TABLE #temp;

END TRY;