Page 1 of 1

How to get previous row value using stage variables

Posted: Sun Nov 03, 2013 10:20 am
by Developer9
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

Posted: Sun Nov 03, 2013 12:57 pm
by ray.wurlod
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.

Code: Select all

svNewPreviousSalary   <----  svPreviousSalary
svPreviousSalary  <----  InLink.salary
When svNewPreviousSalary is being evaluated, svPreviousSalary still contains the value from the previous row.

Posted: Tue Nov 05, 2013 3:05 pm
by Developer9
Thank you ray for the logic..It worked for me.

Here is my output from the stagevariables based on the following order :

Code: Select all

svNewPreviousSalary   <----  svPreviousSalary 
svPreviousSalary  <----  InLink.salary
EID Salary svNewPreviousSalary svPreviousSalary

100 1000 null 1000

200 1500 1000 1500

300 2000 1500 2000

Thanks :)