Incrementing values in datastage going wrong
Moderators: chulett, rschirm, roy
Incrementing values in datastage going wrong
hHi,
INPUT -->
OLDKEY |
1234
1234
1234
1111
2345
2345
Output required --->
OLDKEY | NUMBER
1234 | 001
1234 | 002
1234 | 003
1111 |001
2345 |001
2345 | 002
What i am doing is using a stage variable which stores
SvCurrentOLDKEY -- Stores current oldkey
Sv PreviousOLDKEY -- Stores the previous key
SvNUMBER -- If currOLDKEY = prevOLDKEY then SvNUMBER + 1 else 001
I have initialised SvNumber as 000
bUT the o/p i am getting is first two same records are coming as 001.
what can be wrong.?
Order of stage variables?? or something else.
INPUT -->
OLDKEY |
1234
1234
1234
1111
2345
2345
Output required --->
OLDKEY | NUMBER
1234 | 001
1234 | 002
1234 | 003
1111 |001
2345 |001
2345 | 002
What i am doing is using a stage variable which stores
SvCurrentOLDKEY -- Stores current oldkey
Sv PreviousOLDKEY -- Stores the previous key
SvNUMBER -- If currOLDKEY = prevOLDKEY then SvNUMBER + 1 else 001
I have initialised SvNumber as 000
bUT the o/p i am getting is first two same records are coming as 001.
what can be wrong.?
Order of stage variables?? or something else.
hcdiss
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
Try this :
1. Partition and order input link by key.
2. Keep the order when you defined the stage variable.
3. stgCount as Number and stgOldKey as Varchar/Number ( based on your input field type)
Code: Select all
if link.key <> stgOldKey THEN 1 ELSE stgCount + 1 ===> stgCount
link.key ===> stgOldKey
2. Keep the order when you defined the stage variable.
3. stgCount as Number and stgOldKey as Varchar/Number ( based on your input field type)
Hi Craig,chulett wrote:Still... regardless, for this technique to have any chance of working when you compare current and previous values, you need to set the 'previous' value last or they'll always be the same. ...
Please let me know if I am wrong.
As I know all stage variables and derivation execute one after another according to the order as they defined. When you compare in the first stage variable (stgCount) you have the current value in link.key but it contain the last value in stgOldKey (since it not executed yet). So I think it will work. I tried it for several time and worked fine.
Please let me know.
-
- Participant
- Posts: 3
- Joined: Fri Mar 06, 2009 6:29 pm
Re: Incrementing values in datastage going wrong
First make sure that all your stage variables are in order, dont initialize stage variable to "0" make it "1" and then it should work fine.
If (Sgnew= Sgold) Then (Sgnum+001) Else 001 ==> sgdev
If (Sgdev= Sgnum+001) Then Sgnum+ 001 Else 001 ==> sgnum
sgdev is NUMBER.
Best Regards,
Harsha.
If (Sgnew= Sgold) Then (Sgnum+001) Else 001 ==> sgdev
If (Sgdev= Sgnum+001) Then Sgnum+ 001 Else 001 ==> sgnum
sgdev is NUMBER.
Best Regards,
Harsha.
-
- Participant
- Posts: 3
- Joined: Fri Mar 06, 2009 6:29 pm
Re: Incrementing values in datastage going wrong
First make sure that all your stage variables are in order, dont initialize stage variable to "0" make it "1" and then it should work fine.
If (Sgnew= Sgold) Then (Sgnum+001) Else 001 ==> Sgdev
If (Sgdev= Sgnum+001) Then Sgnum+ 001 Else 001 ==> Sgnum
Sgdev is NUMBER.
Best Regards,
Harsha.
If (Sgnew= Sgold) Then (Sgnum+001) Else 001 ==> Sgdev
If (Sgdev= Sgnum+001) Then Sgnum+ 001 Else 001 ==> Sgnum
Sgdev is NUMBER.
Best Regards,
Harsha.
-
- Participant
- Posts: 63
- Joined: Mon Oct 20, 2008 12:01 am
- Location: Malaysia
-
- Participant
- Posts: 251
- Joined: Mon Jun 09, 2008 5:52 am
-
- Participant
- Posts: 6
- Joined: Tue Jan 29, 2008 3:48 am
- Location: Chennai
Re: Incrementing values in datastage going wrong
Pls,
Try 1:
change the Execution Mode to "Sequential" in Transformer
Try 2:
change the Execution Mode to "Sequential" in Transformer
change the prev stage Execution Mode to "Sequential"
Try 3:
If above is not working, have a sort stage before your Transformer stage.
Set both stage Execution Mode to "Sequential".
Hope this helps you.
Try 1:
change the Execution Mode to "Sequential" in Transformer
Try 2:
change the Execution Mode to "Sequential" in Transformer
change the prev stage Execution Mode to "Sequential"
Try 3:
If above is not working, have a sort stage before your Transformer stage.
Set both stage Execution Mode to "Sequential".
Hope this helps you.
Last edited by santhooosh.c on Sat Mar 21, 2009 3:05 pm, edited 1 time in total.
Santhosh