How Do I Update a Table Column with a Value from Other Columns in the Table? (Magic xpi 3.x)
The Magic xpi Data Mapper Service lets you update fields in database tables. To use fields from the same table as part of the Update expression, you define the same table as both Source and Destination in the Data Mapper. In this case, use the Update operation for the Destination and the Select operation for the Source. Map the required fields from the Source to the Destination.
Another way to update a column in a table with the value of another column(s) in the same table is by changing the SQL statement in the last screen of the database wizard (click here for more information).
In this example Col1 updated with the sum of Col1 and Col2:
|
|
|
1
|
12
|
56
|
2
|
666
|
19
|
15
|
23
|
97
|
Defining the Source
-
Open an existing flow or create a new flow in Magic xpi.
-
Drag the Data Mapper Service to your flow.
-
Click Configuration to open the Source/Destination Management dialog box.
-
In the Source area, create a new Database entry and click Properties to open the Database Schema Properties dialog box.
-
From the DB Operation list, select Select and from the Database Definition drop-down list.
-
Click Wizard to open the Database Wizard.
-
In the Select Tables screen, select Example_Table from the Available tables list and click Add to add it to the Selected table list. Click Next to open the Select the Columns screen.
-
Select Col1 from the Available columns list and click Add to add it to the Selected columns list. Click Next to open the Where Clause screen.
-
Click Next to open the Wizard Result screen and then click Finish to close the wizard and return to the Source/Destination Management dialog box.
Defining the Destination
-
In the Destination area, create a new Database type entry and click Properties to open the Database Schema Properties dialog box.
-
From the DB Operation drop-down list, select Update.
-
Click Wizard to open the Database Wizard.
-
In the Select Tables screen, select Example_Table from the Available tables list and click Add to add it to the Selected table list. 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 and return to the Source/Destination Management dialog box.
-
In the Source/Destination Management dialog box, click Map to open the Data Mapper screen.
-
Map Col1 and Col2 from the Source to Col1 in the Destination.
-
Right-click Col1 in the Destination list and select Properties from the shortcut menu. The Node Properties dialog box opens.
-
Click to the right of the Calculated Value field to open the Expression Editor.
-
Create an expression by doing the following:
-
Select Col1 from the Variables list.
-
Select the + operator from the Operators list.
-
Select Col2 from the Variables list.
The expression that you created appears in the Expression window at the bottom of the Expression Editor. It should look like this:
Col1+Col2
This process will update Col1 with the value of Col1+Col2.