Custom SQL Statements in Database Destinations
This article shows how to use custom SQL statements in database destinations.
The Xtract Universal.iQ database destinations support the use of custom SQL statements in the staging steps of the database.
Create a Custom Statement
To create custom SQL statements in Xtract Universal.iQ:
- Open the Services menu.
- Select a service that uses a database destination, e.g., Microsoft SQL Server.
- Click [ Edit]. The service settings open.
- Open the Destination Settings tab.
- Select the option Custom SQL from one of the following drop-downs:
- Preparation
- Row Processing
- Finalization
- Click [Edit SQL]. The window "Edit SQL" opens.
- Enter your custom SQL statement.
- Click [OK]. The window closes.
- Click [Save].
The custom SQL statement is executed in the selected staging step.
Use Templates
Existing SQL commands can be used as templates to:
- write user-defined SQL expressions and adapt the data load to your needs.
- execute stored procedures that exist in the database.
To generate a Custom SQL command from a template:
- Open the Services menu.
- Select a service that uses a database destination, e.g., Microsoft SQL Server.
- Click [ Edit]. The service settings open.
- Open the Destination Settings tab.
- Select the option Custom SQL from one of the following drop-downs:
- Preparation
- Row Processing
- Finalization
- Click [Edit SQL]. The window "Edit SQL" opens.
- Select a staging command from the dropdown, e.g., Drop & Create.
- Click [Generate Statement]. A new statement is generated.
- Edit the statement to suit your needs or click [Copy] to copy the statement to your clipboard.
- Click [OK]. The window closes.
- Click [Save].
The custom SQL statement is executed in the selected staging step.
Note
The custom SQL code is used for SQL Server destinations. A syntactic adaptation of the code is necessary to use the custom SQL code for other database destinations.
Use Script Expressions
You can use script expressions for Custom SQL commands. The following Xtract Universal.iQ specific custom script expressions are supported:
| Input | Description |
|---|---|
#{Extraction.ExtractionName}# | Name of the service. |
#{Extraction.TableName }# | Name of the database table that data is written to. |
#{Extraction.RowsCount }# | Number of extracted rows. |
#{Extraction.RunState}# | Status of the service (Running, FinishedNoErrors, FinishedErrors, Cancelled). |
#{(int)Extraction.RunState}# | Status of the service as number (2 = Running, 3 = FinishedNoErrors, 4 = FinishedErrors, 6 = Cancelled). |
#{Extraction.Timestamp}# | Timestamp of the service. |
| Example: Verify the existence of a table in a database using 'ExistsTable' | |
|---|---|
Related Links
Written by: Valerie Schipka