The SQL Transformation in Informatica is used to write or use SQL Queries in the middle of the transformation. Using this transformation you can Insert, Delete, or Update rows in a Database. If you are familiar with SQL then you can use this transformation.
In this article we will show you, How to use SQL Transformation to write SQL Queries within the transformation with example. For this example, we are going to use SP Source and Destination tables. From the below screenshot you can see that the Source table has 15 records and Destination table is Empty.
SQL Transformation in Informatica Example
In this example we will show you, How to use SQL Transformation in Informatica to run SQL Script or Query against a database. Before we start configuring, First let me connect with the Informatica repository service. In order to do so, we have to provide the Informatica Admin Console credentials. So, Please provide the appropriate Username and Password, and click the Connect button.
TIP : Here you have to provide the Admin Username and password that you specified while installing the Informatica Server.
Step 1: Create Source Definition for SQL Transformation in Informatica
Once you connected successfully, Please navigate to Source Analyzer and define your Sources. In this example, we are using Sp Source table from SQL Server database as our source definitions. Please refer Database Source in Informatica to understand the steps involved in creating source definition
Step 2: Create Target Definition for SQL Transformation
Please navigate to Target Designer to define the Target. In this example, we are using the existing SQL table (SP Destination) as our target definition. You can refer Create Informatica Target table using Source Definition to understand the process of creating target definition
Step 3: Create Mapping for SQL Transformation in Informatica
To create a new mapping, Please navigate to Mappings menu in Menu Bar and select the Create.. option.
Once you select the Create.. option, a new Mapping Name window will be opened as shown below. Let me provide m_SQLEmp as the mapping name and click OK button.
TIP : Please refer Informatica Mapping article to understand the procedure to create Mapping
Drag and drop the SP Source from Sources folder to the mapping designer. Once you drag the source, Power Center Designer will automatically create the source qualifier transformation (default transformation) for you. I suggest you to refer Source Qualifier Transformation article.
Step 3(a): Create Informatica SQL Transformation
In order to create SQL Transformation in Informatica, Please navigate to Transformation menu in Menu Bar. Next, select the Create.. option
Selecting the Create.. option will open the Create Transformation window as shown below. Please select the SQL Transformation from drop down list and provide the unique name (SQL_Employee) and click on Create button
Clicking the Create button will pop up a new window called SQL Transformation.
- Query Mode: Use this option to write Query directly inside the transformation.
- Script Mode: If your SQL query is saved in a Script file then you can use this option. If you select this option then you have to pass the Script file name.
- DB Type: Please select the Database type. For example, SQL, Oracle etc.
- Static Connection : If you want the connection to be static then select this option.
- Dynamic Connection : Select this option for Dynamic connection.
- SQL Transformation in Passive Mode : By default, SQL transformation is in Active mode. By checking this option you can convert it to Passive Mode.
In this example, we will write a Select Query. So, let me change the DB Type to Microsoft SQL Server and select the Query Mode
By clicking OK will create an Active SQL Transformation for you.
Let me drag all the fields that are available in source definition to SQL Transformation. This will automatically create a set of Input and Output fileds as we shown below.
Double click on the SQL Transformation to edit or configure the transformation. Under the Ports tab, you can see the auto-generated output ports from the source definition inputs.
SQL Ports: This is the most important tab in this transformation. This is where we are going to write Query or selecting script. Before we start writing the script, Let me add one extra field because our target table has New Income column. To do so, click on the New field button
This will add an extra column to output section
Please rename the column to New Income and change its Native type. Next, change the Native Type of each and every Input and Output filed to match the Source and target definition. Once you done with it, click on the Arrow beside the SQL Query.
This will open an SQL Editor with available parameters. As you can see we are using Select Statement to select Yearly income from the SP Source table and adding 45999 to it for each and every Employee record. And the Query is:
SELECT YearlyIncome + 45999 FROM SPSource
WHERE EmpID = ?EmpID?
Check whether everything is OK or not. Remember, whatever the data that we got from the Select Statement will be saved as Output and our output field is New Income. So, New Income = Yearly Income + 45999 where Emp ID = 1, 2, 3, .. 15
Next, Drag and drop the target definition (SP Destination) from Targets folder to the mapping designer. Next, connect the SQL Transformation Output fields with the target definition. You can use the Autolink.. option to connect them.
Before we close the Mapping, Let us Save, and Validate the mapping by going to Mapping Menu bar, and select the Validate option.
Step 4: Create Workflow for SQL Transformation in Informatica
After you finish creating the Mapping, we have to create the workflow for it. PowerCenter Workflow manager provides two approaches to create workflow.
In this example we will create the Workflow manually. To do so, Please navigate to Workflows Menu and select the Create option.
This will open Create Workflow window as shown below. Please provide the unique name (wf_SQLEmployee) and leave the default settings.
Once we created the workflow, our next step is to create session task for our mapping.
Step 4(a): Create a Session for SQL Transformation in Informatica
There are two types of sessions in informatica:
For this example we created a Non-reusable Session. In order to create Non-reusable Session, Please navigate to Tasks Menu and select the Create option as shown below.
Please provide a unique name for this session. Here, we are naming it as s_SQLEmployee. Once you click on the Create button, a new window called Mappings will be opened. Here you have to select the mapping that you want to associate with this session i.e., m_SQLEmp.
Double click on the Session task will open the Edit Tasks window. Within Properties Tab
$Source connection value: This property will store the relational source information in $Source variable. So, click on the Arrow we marked below, and select the Informatica Source as the source information.
$Target connection value: This property will store the relational target information in $Target variable. So, click on the Arrow we marked below, and select the Informatica Target as the Target information.
Within the mappings tab, we have to configure the Source, and Target Connections. First, let us configure the source connections by clicking on the SQ_SPSource source present in the Sources folder.
With in the Connections, click on the Arrow button beside the Relational type, and use the Connection variable that we created in our previous step i.e., $Source
Now, we have to configure the Target Connection. So, click on the SPDestination present in the Targets folder. With in the Connections, click on the Arrow button beside the Relational type, and use the Connection variable $Target
Lastly, we have to configure the SQL Transformation. So, click on the SQL_Employee present in the Transformations folder. With in the Connections, click on the Arrow button beside the Relational type, and use the Connection variable $Source. This is because we used the Select Statement to select records from Informatica Source.
As we are done with the Session configuration. Let us navigate to Workflows Menu and select the Validate option to validate the Workflow.
Now, Let me start the Workflow. To do so, navigate to Workflows menu, and select the Start Workflow option.
Thank You for Visiting Our Blog