How Do I Use Dynamic WHERE Clauses? (Magic xpi 4.7)
You can use the Magic xpi Data Mapper utility to create SQL statements. There are two types of WHERE clause statements: static and dynamic. This topic explains when and how to use the statements.
|
|
|
Applies to
|
Source and Destination
|
Destination (Update and Delete)
|
When to use
|
When the value is in a variable.
|
When the value is not in a variable.
|
Displayed in Data Mapper screen
|
No
|
Yes
|
Syntax
|
Table_column = <?Variable_Name?>
|
table column = <!?Data_holder_name?!>
|
Data types
|
Variable can be any data type supported by Magic xpi.
|
Data holder can be any data type supported by Magic xpi.
|
The example below shows how to create a dynamic WHERE clause. The steps in the example are divided into these two stages:
The steps assume that your integration project includes a table called exampleTable_Des with the following properties:
|
|
|
|
Key1
|
A
|
56
|
D
|
Key2
|
B
|
78
|
E
|
Key3
|
C
|
99
|
F
|
It is also assumed that the integration project includes a second table, exampleTable_Sour, with the same structure as exampleTable_Des.
The purpose of this example is to delete records from the exampleTable_Des table, which existed in the exampleTable_Sour table.
Defining the Source
-
In the Magic xpi Studio, drag the Data Mapper utility to your flow.
-
Double-click or right-click on the Data Mapper and click Configuration to open the Data Mapper window.
-
From the Toolbox's Mapper Schemas section, drag a Database type into the Source area of the Data Mapper window.
-
In the Database Definition drop-down list, select your database.
-
Click Wizard to open the Database Wizard.
-
In the Select Tables screen, select the exampleTable_Sour table and click Next to open the Select the Columns screen.
-
Select the Table_Key column and click Next to open the Where Clause screen.
-
Click Next to go to the Wizard Result screen and then click Finish to close the wizard.
Defining the Destination
-
From the Toolbox's Mapper Schemas section, drag a Database type into the Destination area of the Data Mapper window.
-
In the Database Definition drop-down list, select your database.
-
Click Wizard to open the Database Wizard.
-
In the DB Operation list, choose Delete.
-
In the Select Tables screen, select the exampleTable_Des table and then click Next to open the Where Clause screen.
-
From the Available Columns list, double-click the Table_Key column and in the Where Clause Text area add the following: =<!?MyKey?!>. The text should therefore appear as follows: Table_Key=<!?MyKey?!>.
Note: MyKey is a data holder, not a predefined variable.
-
Click Next to go to the Wizard Result screen and then Finish to close the wizard.
This sets up the deletion of all the records in the exampleTable_Des table, records that are also in the exampleTable_Sour table.
|
If this example had used a variable instead of mapping the column in the exampleTable_Sour table to the data holder, only one record would have been deleted from the exampleTable_Des table.
|