Current Indicator for duplicate records

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
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Current Indicator for duplicate records

Post by kogads »

Hi All,

I have records which look like below

RecId Date
1 20100614
2 20100614
3 20100614
3 20100615
3 20100616

The output should look like

RecId Date Current Indicator
1 20100614 Y
2 20100614 Y
3 20100614 N
3 20100615 N
3 20100616 Y

Can any one please suggest a logic for this.

Thanks...
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Use sort stage and set Create Key Change column to true which creates a field KeyChange.

Code: Select all

Current Indicator : If KeyChange = 1 then 'N' Else 'Y'
You are the creator of your destiny - Swami Vivekananda
kogads
Premium Member
Premium Member
Posts: 74
Joined: Fri Jun 05, 2009 5:36 pm

Post by kogads »

anbu wrote:Use sort stage and set Create Key Change column to true which creates a field KeyChange.

Code: Select all

Current Indicator : If KeyChange = 1 then 'N' Else 'Y'
I used the sort stage with the logic you mentioned. i used the RecId as sort key and set the create key change column option. The output is not what iam expecting.

RecId Date Current Indicator
1 20100614 Y
2 20100614 Y
3 20100614 Y
3 20100615 N
3 20100616 N

this is the output i got. Instead i tried with 2 sort stages.In the 1st i sorted on Date in descending order with hash partition on recId and in 2nd sort stage I used same partition and sort key as RecId with create change key column option true.Then I got the right result as

RecId Date Current Indicator
1 20100614 Y
2 20100614 Y
3 20100614 N
3 20100615 N
3 20100616 Y

Can any one suggest how to get this result with just one sort stage instead of 2.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Set create change key column to true in the first sort. You dont need second sort to do this.

Then use

Code: Select all

Current Indicator : If KeyChange = 1 then 'Y' Else 'N'
You are the creator of your destiny - Swami Vivekananda
Post Reply