Page 1 of 1

Merging Column Data

Posted: Tue Mar 13, 2012 9:24 am
by mgray412
I need to combine data from several columns into 1 column only showing any duplicates only once in the output column. For example:

Col 1 = A
Col 2 = B
Col 3 = A
Col 4 = C
Col 5 = B

The output column should be: A B C

How can I do this in DataStage?

Thanks in advance for all your help

Re: Merging Column Data

Posted: Tue Mar 13, 2012 9:48 am
by kwwilliams
If the number of columns is fixed then you could do it in stage variables.

svCol2 = if Count(Column1, Column2) > 0 Then '' Else Column2
svCol3 = if Count(Column1:svCol2,Column3) > 0 Then '' Else Column3
svCol4 = if Count(Column1:svCol2:svCol3,Column4) > 0 Then '' Else Column4
svCol5 = if Count(Column1:svCol2:svCol3:svCol4,Column5) >0 Then '' Else Column5

Answer = Column1:svCol2:svCol3:svCol4:svCol5

Count is the number of occurences of a substring within a string, if the count is greater than 0 it means the value already existed and you wouldn't want to add it to your final answer, so you set it to blank.

Re: Merging Column Data

Posted: Tue Mar 13, 2012 12:46 pm
by mgray412
Keith,

That solved my problem. Thanks for your help!!