Logic needed

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
chrisjones
Participant
Posts: 194
Joined: Thu May 11, 2006 9:42 am

Logic needed

Post by chrisjones »

Hi ,
Please help me how to implement this logic in DS.

soure is coming like this

code1 val1 group1
____________________________________
1 p abc
0 p abc

1 a fpg
0 a fpg

------------------------------------------------


out put should be like this

code1_val1 group1
------------------------------
1p0p abc
1a0a fpg

Thanks in advance,
Chris
Thanks,
Chris Jones
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

Re: Logic needed

Post by DSkkk »

code1 val1 group1
____________________________________
1 p abc
0 p abc

1 a fpg
0 a fpg

------------------------------------------------


Before getting to design.. i wanted to know .. How many times can a Group appear in a file. i.e., say do u have any requirement that "abc" appears only twice or at a max. for N times.

regards.
Kiran.
g.kiran
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Welcome aboard 8)
Sort your incoming data by val1.
Use two stage variables to do the group changing dance, say cond and prevVal. They should be in the same order as i specified. cond first and prevVal second.

Code: Select all

cond- if @INROWNUM =1 OR INLINK.val1 = prevVal then cond:INLINK.code1:INLINK.val1 else INLINK.code1:INLINK.val1
prevVal- INLINK.val1
after doing that your output data will look like

Code: Select all

p     1p          abc
p     1p0p      abc
a     1a          fpg
a     1a0a      fpg
pass the output through an aggregator, group on the code1_val1 and group1 and specify the "Last" option for middle column
that will give you your desired output.

Code: Select all

p     1p0p    abc
a     1a0a    fpg
Regards,
Last edited by DSguru2B on Fri Jun 23, 2006 7:23 am, edited 2 times in total.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chrisjones
Participant
Posts: 194
Joined: Thu May 11, 2006 9:42 am

Re: Logic needed

Post by chrisjones »

Hi,
In my requirement "abc" appears only twice .

DSkkk wrote:code1 val1 group1
____________________________________
1 p abc
0 p abc

1 a fpg
0 a fpg

------------------------------------------------


Before getting to design.. i wanted to know .. How many times can a Group appear in a file. i.e., say do u have any requirement that "abc" appears only twice or at a max. for N times.

regards.
Kiran.
Thanks,
Chris Jones
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Try to go through my logic. In that, it doesnt matter how many times abc or for that matter any other value exist. All you need is to be sorted by val1 and the design will take care of the rest.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
sud
Premium Member
Premium Member
Posts: 366
Joined: Fri Dec 02, 2005 5:00 am
Location: Here I Am

Post by sud »

[quote="DSguru2B"]Try to go through my logic. In that, it doesnt matter how many times abc or for that matter any other value exist. All you need is to be sorted by val1 and the design will take care of the rest.[/quote

That will definitely work, but if you know for sure that it appears twice, I would always go for a self join query. I always prefer finishing such stuff at the database end itself. :)
It took me fifteen years to discover I had no talent for ETL, but I couldn't give it up because by that time I was too famous.
Dharma
Participant
Posts: 3
Joined: Fri Apr 14, 2006 8:46 am

Re: Logic needed

Post by Dharma »

HI

use this select statement u can get as u required

select max(code1) || max(var1) ||min(code1)||min(var1),group1 from abc group by group1

Thanks

Dharma
chrisjones wrote:Hi ,
Please help me how to implement this logic in DS.

soure is coming like this

code1 val1 group1
____________________________________
1 p abc
0 p abc

1 a fpg
0 a fpg

------------------------------------------------


out put should be like this

code1_val1 group1
------------------------------
1p0p abc
1a0a fpg

Thanks in advance,
Chris
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

DSguru2B has a good solution for you to use.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply