How to find second Transaction date in a Table

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
arundwh
Participant
Posts: 3
Joined: Thu Dec 03, 2009 2:30 am

How to find second Transaction date in a Table

Post by arundwh »

Find the second day transaction amount for a Accnt_id.

Ex: Epected records are marked in red.
Acct_Hist
Accnt_id, Trans_Dt, Seq_Num
1001 23-10-09 1
1001 24-10-09 1
1001 25-10-09 1
1002 26-10-09 1
1002 27-10-09 1
1002 27-10-09 2
1002 28-10-09 1

Output:
Accnt_id, Trans_Dt ,Seq_Num
1001 24-10-09 1
1002 27-10-09 1
1002 27-10-09 2
Last edited by arundwh on Fri Dec 04, 2009 12:47 am, edited 1 time in total.
gssr
Participant
Posts: 243
Joined: Fri Jan 09, 2009 12:51 am
Location: India

Post by gssr »

Can you be Specific?

You are getting all the Trans_Date other than the first one?
Is that your requirement?
If "Yes" then ,why did you drop the date of 25/10/09 for 1001?
RAJ
Sreenivasulu
Premium Member
Premium Member
Posts: 892
Joined: Thu Oct 16, 2003 5:18 am

Post by Sreenivasulu »

Do a group by on transaction date. put this to a dataset with the record order.
Then get the second record by doing @INROWNUM =2
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Assuming you are checking by the ids following with same date and incrementing sequence, you can

1.) Sort data on id and date with keyChange capture
2.) Set a stage variable - say svIncrNum - to zero on change of id
3.) if the next id is same with incrementNumber = svIncrNum + 1, then take it. else reset the 'previous' values.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Sort by transaction date in ascending order, then use Remove Duplicates stage to preserve the last from each group. (I'm assuming a maximum of two rows per group.)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply