Create Sequence Number for the Duplicate Enteries

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
pradeep_nov18
Participant
Posts: 92
Joined: Wed Mar 05, 2008 4:09 am
Location: chennai
Contact:

Create Sequence Number for the Duplicate Enteries

Post by pradeep_nov18 »

I have requirement to generate the sequence number for the duplicate enteries.

For Example

ID,Seq_number
10,1
10,2
20,1
20,2
30,1
30,2
30,3
30,4

Any suggestion Appreciated

Thanks In Advance
pradeep.v
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Use a stage variable to count the number of successive duplicate entries

"svSeqNumber" derivation : "if In.ID = svLastID THEN svSeqNumber+1 ELSE 1"
"svLastID" derivation "In.ID"

The order of the two variables is important.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can also use the Sort stage to put them in order and add a Key Change column, which would make your stage variable derivation even easier (you would only need one).
-craig

"You can never have too many knives" -- Logan Nine Fingers
prajesh
Participant
Posts: 7
Joined: Sun Apr 24, 2011 4:52 am

Re: Create Sequence Number for the Duplicate Enteries

Post by prajesh »

Hi Pradeep,

u didnt mentioned source if it's database we can generate sequence no at source stage using user defined query:

I have requirement to generate the sequence number for the duplicate enteries.

select ID,RANK() OVER (PARTITION BY ID ORDER BY ID) Seq_number from schemaname.tabname

OR

using stages:
seq.file----->cpy------>aggr(grpby.key ID and caltype=count)--->seq
| |
| |
|
(Key ID)Joinstage(inner)|

In Aggr u can use grouping id as ID and calc type=countrows

In join stage inner join with key column as ID


Regards,
Rajesh
prajesh
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

U is a fairly common Burmese name. At least one of our posters is named U.

The second person personal pronoun in English is spelled "you". Not "u".
Please strive to maintain a professional standard of written English on DSXchange. It is not a mobile telephony device, and you are not limited to 140 characters, so there is no reason to employ SMS-style abbrevations.
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