Wednesday, October 26, 2011

Useful Scenario

I have a source table like,
Empno   ename              sal
-------   ----------       ----------
7001       kumar               0
7499       allen                2000
7521       ward               1250
7654       martin            1250
7698       blake               2850
7782       clark                2450
7839       king                 6000
7844       turner             1500
7900       james              950
7934       miller              2000
        Now my target table should look like,
Empno     ename      sal                 prevsal
-------     --------   ------        ----------
7001         kumar       0                   null
7499         allen         2000               0
7521         ward        1250               2000
7654         martin     1250              1250
7698         blake        2850             1250
7782         clark         2450             2850
7839          king         6000             2450
7844          turner     1500             6000
7900          james      950               1500
7934          miller       2000            950

Solution:

                                       Using 'lag' function in oracle, we can achieve this easily.Design The mapping as shown in the above image.And Write the sql query in the source qualifier as follows,
Select
Emp.empno,
Emp.ename,
Emp.sal,
Lag(emp.sal,1) over(order by emp.sal) as prevsal
From
Emp
This will bring our desired output.

2 comments:

  1. we can achive this with informatica also..Here is the same
    Empno
    ename

    sal
    V_count=V_count+1
    V_salary=IIF(V_count=1,NULL,V_prev_salary)
    V_prev_salary=sal
    O_prev_salary=V_salary

    ReplyDelete