Page 1 of 1

How to find second Transaction date in a Table

Posted: Thu Dec 03, 2009 3:24 am
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

Posted: Thu Dec 03, 2009 3:52 am
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?

Posted: Thu Dec 03, 2009 3:52 am
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

Posted: Thu Dec 03, 2009 5:37 am
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.

Posted: Thu Dec 03, 2009 2:30 pm
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.)