Click or drag to resize

Encapsulate as Inline Function

The Encapsulate as Inline Function command convert the selected code into a new inline table-valued function and optionally replace it with a SELECT from the new function.

This topic contains the following sections:

Usage
Note 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 function:

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

2. On the SQL Enlight->Refactor menu, click Encapsulate as Inline Function .

3. The Encapsulate as Inline Function dialog box is displayed.

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

refactoring-3

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

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

6. Modify the order and the type of the parameters using the Parameters grid.

Note Note

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

7. Review the generated script in the Preview box and modify it if necessary.

8. 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.

9. Click Apply button to apply the changes.

Parameters

The parameters of the new objects are determined from the variables which are referenced in the selected code.

SQL Enlight automatically resolves the data type and the direction of these parameters. If a variable is used, but declared nowhere in the script, its declaration in the resulting script will have sql_variant data type.

See Also

Other Resources