Page 1 of 1

Datastage Senario?

Posted: Mon Mar 03, 2014 4:37 am
by A_SUSHMA
I need the below output please let me know how to do in ds


Input
101 1000
101 2000
101 3000
201 1000
201 4000

Output
101 1000
101 3000
101 6000
201 1000
201 5000

Reply

Posted: Mon Mar 03, 2014 5:01 am
by ssnegi
In Transformer Hash Partition & Sort COL1 ascending.
Dont partition sort only COL2 Ascending. Then use stage variables.

svsum : if DSLINK.COL1 = svCOL1old then svCOL2 + DSLINK.COL2 else DSLINK.COL2
svCOL1old : DSLINK.COL1
svCOL2 : svsum

Output Col1 : DSLINK.COL1
Output Col2 : svsum

Posted: Mon Mar 03, 2014 8:06 am
by chulett
Or use a Sort stage to generate a Key Change column on the first field and then all you need is:

Code: Select all

svRunningTotal: If KeyChange then COL2 else svRunningTotal + COL2
And of course, mind your partitioning.