Page 1 of 1

Logic needed

Posted: Thu Jun 22, 2006 12:27 pm
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

Re: Logic needed

Posted: Thu Jun 22, 2006 12:51 pm
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.

Posted: Thu Jun 22, 2006 12:54 pm
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,

Re: Logic needed

Posted: Thu Jun 22, 2006 2:04 pm
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.

Posted: Thu Jun 22, 2006 2:05 pm
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.

Posted: Thu Jun 22, 2006 4:13 pm
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. :)

Re: Logic needed

Posted: Thu Jun 22, 2006 6:33 pm
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

Posted: Thu Jun 22, 2006 7:01 pm
by kcbland
DSguru2B has a good solution for you to use.