How to create sequence number per ID?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
bharathappriyan
Participant
Posts: 47
Joined: Fri Sep 23, 2005 6:01 pm

How to create sequence number per ID?

Post by bharathappriyan »

Hi,

I need to create sequence number per ID.

For ex:

Input is ID column.
Output is ID and sequence number per ID.

ID Sequence_Number
100 1
100 2
101 1
102 1
102 2
102 3
102 4
103 1

If the Current records ID matches with the previous records ID, i need to increase the sequence number otherwise it should be one.

Is it possible to this in a single job itself?

Please guide me.

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

Post by ArndW »

This easy to do using 2 stage variables in a transform stage. Declare
StageSequence as IF In.ID=LastID THEN StageSequence+1 ELSE 1
LastID as In.ID
Sunshine2323
Charter Member
Charter Member
Posts: 130
Joined: Mon Sep 06, 2004 3:05 am
Location: Dubai,UAE

Post by Sunshine2323 »

Hi bharathappriyan,

Declaring a stage variable

StgCounter=if RowProcCompareWithPreviousValue(Input.ID) then StgCounter+1 else 1
Warm Regards,
Amruta Bandekar

<b>If A equals success, then the formula is: A = X + Y + Z, X is work. Y is play. Z is keep your mouth shut. </b>
--Albert Einstein
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

All fine guys but the real question is do you need to preserve the sequences between job runs or is every run independant and can reinitialyze the sequences?
If not then the sugested logic works fine.
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
aditya
Charter Member
Charter Member
Posts: 41
Joined: Sat May 28, 2005 7:32 am

Post by aditya »

Ask the DBA to create a sequence and use it in you query. You can also create one in the ERWIN data modeller and pass it over the script to the DBA.

Thanks
Aditya.
Post Reply