Hello Everybody,
I have a requirement to generate previous row value where first record should populate null .
Input :
Emp_ID salary
100 1000
200 1500
300 2000
Output:
Emp_ID salary Previous_Salary
100 1000 NULL
200 1500 1000
300 2000 1500
I guess this can be performed by writing staging variables to compare the rows .
Please somebody provide me the logic to generate the stage variables
Thanks
How to get previous row value using stage variables
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 187
- Joined: Thu Apr 14, 2011 5:10 pm
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Doesn't Search work for you? This technique has been described on a number of occasions.
In your case you need two stage variables. Let's call them svNewPreviousSalary, which will become the value of the Previous_Salary output column, and svPreviousSalary, which will be used to "remember" the previous salary. Each is initialized to SetNull().
Derivations are as follows.
When svNewPreviousSalary is being evaluated, svPreviousSalary still contains the value from the previous row.
In your case you need two stage variables. Let's call them svNewPreviousSalary, which will become the value of the Previous_Salary output column, and svPreviousSalary, which will be used to "remember" the previous salary. Each is initialized to SetNull().
Derivations are as follows.
Code: Select all
svNewPreviousSalary <---- svPreviousSalary
svPreviousSalary <---- InLink.salary
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Premium Member
- Posts: 187
- Joined: Thu Apr 14, 2011 5:10 pm
Thank you ray for the logic..It worked for me.
Here is my output from the stagevariables based on the following order :
EID Salary svNewPreviousSalary svPreviousSalary
100 1000 null 1000
200 1500 1000 1500
300 2000 1500 2000
Thanks
Here is my output from the stagevariables based on the following order :
Code: Select all
svNewPreviousSalary <---- svPreviousSalary
svPreviousSalary <---- InLink.salary
100 1000 null 1000
200 1500 1000 1500
300 2000 1500 2000
Thanks