SQL Snippets
SQL snippets are small pieces of SQL code that can be used and reused throughout Prepare instances to speed up development. SQL Snippets can be used when applying field level transformations. They can also be applied in Views, Stored Procedures, User Defined Functions, and Script Actions.
Add a SQL Snippet
-
Under Tools, select Snippets.
-
Click Add and then select SQL Snippet.
-
Provide a Name, Description, and Formula for the snippet. Highlight the parameter in the formula and click Add Parameter.
-
Under Parameters, change the Type to match what the parameter represents. You have the following options:
- Table
- Field
- Database
- User Defined Function
- Stored Procedure
- Value
- Click OK.
Using a SQL Snippet
Apply the snippet using one of the following methods, which may vary depending on where or how the snippet is being used.
Field transformation
- Expand the Scripts folder.
- Right-click the field.
- Select Add SQL Snippet Transformation.
- Select the snippet from the list that appears on the right.
Stored procedure
- Expand the Scripts folder.
- Right-click Stored Procedures and then select Add Snippet Stored Procedure.
- Select the snippet from the list that appears on the right.
User defined function
- Expand the Scripts folder.
- Right-click the User Defined Function folder and then select Add Snippet User Defined Function.
- Select the snippet from the list that appears on the right.
Custom step
- Expand the Scripts folder.
- Right-click the Script Actions folder and then select Add Snippet Custom Step.
- Select the snippet from the list that appears on the right.
View
- Right-click the Views folder and then select Add Snippet View.
- Select the snippet from the list that appears on the right.
Map parameters
-
Map the available fields to the parameters in the snippet. Drag the field(s) from the list on the right and drop the field on the Object Name/Value column for the relevant variable. The Object Name/Value column and Variant column will populate automatically.
- Click OK.
Edit or Delete a Snippet
Under Tools, select Snippets. Select the snippet and click Edit or Delete.
Show Snippet Usage
Under Tools, select Snippets. Select the snippet and click Show Usage.
Troubleshooting
If the snippet is returning NULL values, for example in a custom transformation, and the table where the snippet is being applied is an incremental table, perform a full load to ensure that values are updated for the snippet.