Microsoft SQL Server DECLARE and EXECUTE
PowerBuilder requires a declarative statement
to identify the database stored procedure that is being used and
a logical name that can be referenced in subsequent SQL statements.
The general syntax for declaring a procedure is:
1 |
DECLARE <span>logical_procedure_name</span> PROCEDURE FOR<br> <span>SQL_Server_procedure_name</span><br> @<span>Param1</span> = <span>value1</span>, @<span>Param2</span> = <span>value2</span>, <br> @<span>Param3</span> = <span>value3</span> OUTPUT,<br> {USING <span>transaction_object</span>} ; |
where logical_procedure_name can
be any valid PowerScript data identifier and SQL_Server_procedure_name is
the name of the stored procedure in the database.
The parameter references can take the form of any valid parameter
string that SQL Server accepts. PowerBuilder does not inspect the
parameter list format except for purposes of variable substitution.
You must use the reserved word OUTPUT to indicate an output parameter.
The USING clause is required only if you are using a transaction
object other than the default transaction object (SQLCA).
Example 1
Assume a stored procedure proc1 is defined as:
1 |
CREATE PROCEDURE proc1 AS<br> SELECT emp_name FROM employee |
To declare that procedure for processing within PowerBuilder,
enter:
1 |
DECLARE emp_proc PROCEDURE FOR proc1; |
Note that this declaration is a nonexecutable statement, just
like a cursor declaration. Where cursors have an OPEN statement,
procedures have an EXECUTE statement.
When an EXECUTE statement executes, the procedure is invoked.
The EXECUTE refers to the logical procedure name:
1 |
EXECUTE emp_proc; |
Example 2
To declare a procedure with input and output parameters, enter:
1 |
DECLARE sp_duration PROCEDURE FOR pr_date_diff_prd_ken<br> @var_date_1 = :ad_start,<br> @var_date_2 = :ad_end,<br> @rtn_diff_prd = :ls_duration OUTPUT; |