Looping Date values in Transformers

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
skumar
Participant
Posts: 88
Joined: Thu May 25, 2006 5:11 am
Location: Hyderabad

Looping Date values in Transformers

Post by skumar »

Hi All,


I have a single record from source which contains minimum date - 2015/10/01 and maximum date - 2015/10/31.
Now, In target I want to generate in between dates using loop variables. So my target should contain 31 records including the min and max dates.

can some one help me on this.


Thanks
skumar
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What have you tried?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

HINT:
DaysSinceFromDate AND DateFromDaysSince
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

You may leverage Oracle hierarchical functions thru Sparse Lookup for this.

Code: Select all

SELECT (to_date(:STARTDATE,'YYYYMMDD') + (level - 1)) DateListVal FROM dual
CONNECT BY level <= (to_date(:ENDDATE,'YYYYMMDD') - to_date(:STARTDATE,'YYYYMMDD') + 1)
STARTDATE and ENDDATE: Input date values in YYYYMMDD / VarChar format.
DateListVal: Output date list / Date format.
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Back to generating in between dates using loop variables, have you tried any function combined with the @ITERATION value?
Choose a job you love, and you will never have to work a day in your life. - Confucius
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yah, not really sure why Oracle got thrown into the mix. It doesn't answer the question that was asked and no database was mentioned, let alone a specific one. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
skumar
Participant
Posts: 88
Joined: Thu May 25, 2006 5:11 am
Location: Hyderabad

Post by skumar »

I tried using the loop variables with @ITERATION function. it worked well for me. here is the logic.

Stage variable1 - Min Date
Stage Variable2 -Max Date
Stage Variable3 - JulianDay(MaxDate)-JulianDay(MinDate)

Now, In loop constraint @ITERATION <=StageVariable3
In derivation of LoopVar - DateoffsetbyDays(Stagevariable1,@ITERATION-1)

I got the answer hence i am marking it as resolved. thanks all for your support

Thanks
skumar
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Skumar ... Cool.

And to answer previous questions ... Inspired by creative solutions and thinking outside of the box, that I have seen in this forum, like suggestions to leverage server job's capabilities when the OPs question was in parallel forum or advising them to use an Oracle literal when title mentioned bind variables ;-)

Unless it is an interview question, developers are more interested in solving the issue, than strictly using a particular stage. In this case, preexisting code for similar req (date dim creation) was shared with OP.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yeah, yeah, whatever.

:P
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply