Derive Multiple Rows from two columns based on Range

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
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Derive Multiple Rows from two columns based on Range

Post by just4geeks »

I have to derive Multiple Rows from two columns based on Range :

For Example:
Source File looks like:
Col1 Col 2 Col3
A 2004 2006
B 1999 2002

From this I have to a derive a column (Col4) which should have all values within the range of Col2 and col3

So My Output file should look like:

Col1 Col4
A 2004
A 2005
A 2006
B 1999
B 2000
B 2001
B 2002

I will appreciate if anybody can help me designing this logic efficiently in DataStage 7.0 server version.

Thanks in advance,

Take care!
Last edited by just4geeks on Mon Sep 28, 2009 3:56 pm, edited 1 time in total.
Attitude is everything....
rachit82
Premium Member
Premium Member
Posts: 41
Joined: Thu Jul 17, 2008 9:49 am

Re: Derive Multiple Rows from two columns based on Range

Post by rachit82 »

just4geeks wrote:I have to derive Multiple Rows from two columns based on Range :

For Example:
Source File looks like:
Col1 Col 2 Col3
A 2004 2006
B 1999 2002

From this I have a derive a column (Col4) which should have all values within the range of Col2 and col3

So My Output file should look like:

Col1 Col4
A 2004
A 2005
A 2006
B 1999
B 2000
B 2001
B 2002

I will appreciate if anybody can help me designing this logic efficiently in DataStage 7.0 server version.

Thanks in advance,

Take care!
Is this a file you get or is it a table that is your source?
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Post by just4geeks »

Source is a file.

Thanks!
Attitude is everything....
rachit82
Premium Member
Premium Member
Posts: 41
Joined: Thu Jul 17, 2008 9:49 am

quick and easy solution.

Post by rachit82 »

just4geeks wrote:Source is a file.

Thanks!
Quick and dirty way would be to put it on a staging table and then do a between statement where you can pass the year number as a parameter which would yeild the desired result.

If you do not want to use staging tables then tell me more about this range. Is it always a date or what values do these columns have?
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Post by just4geeks »

Thanks for the response!

The 2 columns ( Col2 and col3 ) will always have year values. For example 1999, 2001, 2002, 2003 etc.

Take care!
Attitude is everything....
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Post by just4geeks »

Any suggestions are most welcome for this interesting problem.
source is a flat file and I can't use staging table. I have to write DataStage logic to accomplish this.
Take care!
Attitude is everything....
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What is your target? :?

Build a routine with a FOR loop, appending the values from your range. If your target is another sequential file, you can even add CHAR(10) characters between them to create individual records from the returned string. Crude illustration:

Code: Select all

YearString=""
FOR year = Col2 to Col3 step 1
  YearString := Col1:",":year:CHAR(10)
NEXT year
Ans=YearString
Hopefully that will get the creative juices flowing...
-craig

"You can never have too many knives" -- Logan Nine Fingers
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Post by just4geeks »

Thanks Craig!
My Traget is also a sequential file.
I am not well versed in writing routines but I will try this one tomorrow.
Take care!
Attitude is everything....
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

You can perform a lookup to your Calendar / Time dimension's year column using BETWEEN clause.
Post Reply