Contents 

Ubitsoft SQL Enlight Online Help

Encapsulate As Stored Procedure
Encapsulate As Scalar Function
Encapsulate As Inline Function

Using the Encapsulate As... commands you can generate script for creating new stored procedure,scalar
or inline table-valued function from selected SQL code. The source script can be modified in a way that the
encapuslated script to be replaced with a reference to the new procedure or function.

The parameters of the new procedure or function are determined from the variables which are used in the selected code.
SQL Enlight automatically determines the data type and the direction the parameters and if a variabe is used, but
declared nowhere in the script, it's parameter will have sql_variant data type.

Note: Statements creating or altering stored procedures, functions,triggers,views,rules and defaults cannot be encapsulated.


Encapsulate As Stored Procedure

To encapsulate code as a new stored procedure:

1. Select the script that you want to use for the new stored procedure.

2. On the SQL Enlight menu, click Encapsulate As Stored Procedure....

3. The Encapsulate As Stored Procedure dialog box is displayed.

Encapsulate As Stored Procedure

The SQL script for the creation of the stored procedure is displayed in the Preview box.

4. Type the name of the owner in the Owner edit box.

5. Type the name of the procedure in the Name edit box.

Note: The procedure name is not checked for duplicate names. If a stored procedure with this owner and name
already exists, the script will fail.

6. Review and if requiered modify the generated script in the Preview box.

7. Select Modify source script to reference the new object if you want SQL Enlight to modify the originating
script and replace the encapsulated code with reference to the new procedure.The generated reference to the
new stored procedure is an EXECUTE statement with the procedure parameters.

8. Click Apply button to apply the changes.


Encapsulate As Scalar Function

Note: Statements creating or altering stored procedures, functions,triggers,views,rules and defaults cannot be encapsulated.

To encapsulate code as a new scalar functon:

1. Select the script that you want to use for the new scalar functon.

2. On the SQL Enlight menu, click Encapsulate As Scalar Function....

3. The Encapsulate As Scalar Function dialog box is displayed.
The SQL script for the creation of the scalar functon is displayed in the Preview box.

4. Type the name of the owner in the Owner edit box.

5. Type the name of the function in the Name edit box.

Note: The function name is not checked for duplicate names. If a function with this owner and name
already exists, the script will fail.

6. Review and if requiered modify the generated script in the Preview box.

7. Select Modify source script to reference the new object if you want SQL Enlight to modify the originating
script and replace the encapsulated code with reference to the new function. The generated reference to the
new scalar function is an SELECT statement selecting the return of the function call.

8. Click Apply button to apply the changes.


Encapsulate As Inline Table-Valued Function

Note: Only SELECT statements can be encapsulated in inline table-valued functions.SELECT INTO and
SELECT @local_variable statements are not allowed.

To encapsulate code as a new scalar functon:

1. Select the script that you want to use for the new functon.

2. On the SQL Enlight menu, click Encapsulate As Inline Function....

3. The Encapsulate As Inline Function dialog box is displayed.
The SQL script for the creation of the functon is displayed in the Preview box.

4. Type the name of the owner in the Owner edit box.

5. Type the name of the function in the Name edit box.

Note: The function name is not checked for duplicate names. If a function with this owner and name
already exists, the script will fail.

6. Review and if requiered modify the generated script in the Preview box.

7. Select Modify source script to reference the new object if you want SQL Enlight to modify the originating
script and replace the encapsulated code with reference to the new function. The generated reference to the
new inline table-valued function is an SELECT statement selecting from return of the function.

8. Click Apply button to apply the changes.