How to get previous row value using stage variables

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Developer9
Premium Member
Premium Member
Posts: 187
Joined: Thu Apr 14, 2011 5:10 pm

How to get previous row value using stage variables

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Developer9
Premium Member
Premium Member
Posts: 187
Joined: Thu Apr 14, 2011 5:10 pm

Post 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 :)
Post Reply