passing date parameter

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

Krazykoolrohit
Charter Member
Charter Member
Posts: 560
Joined: Wed Jul 13, 2005 5:36 am
Location: Ohio

passing date parameter

Post by Krazykoolrohit »

I tried the search but couldnt find anything to help me.

I am passing the following SQL in the DB2 API. i need to extract data for the last week

Code: Select all

Z_PLCMT between 'DATE('#Week_Start_Date#')' || '-00.00.00.000000' and 'DATE('#Week_End_Date#')' || '-00.00.00.000000'

the values for Week_Start_Date being passed = 14347 and for Week_End_Date = 14341

the error message: SQL0104N An unexpected token "14347" was found following "". Expected tokens may include: "+ - AND". SQLSTATE=42601

Can you please point out where i am doing anything wrong in the syntax?
Krazykoolrohit
Charter Member
Charter Member
Posts: 560
Joined: Wed Jul 13, 2005 5:36 am
Location: Ohio

Post by Krazykoolrohit »

the following worked

Code: Select all

Z_PLCMT between char(DATE(#Week_Start_Date#)) || '-00.00.00.000000' and char(DATE(#Week_End_Date#)) || '-00.00.00.000000'
but have another query now.

DATE(14347) is not giving the output as '04-06-2007' instead its just passing 14347.
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

Is it the Julian Date? I don't see any date function which will convert an Integer representation to date format using DATE function.I am not sure but might be you can do something like this:

Code: Select all

 DATE('Jan 1 0001' + 14347 DAYS) 
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

14347 could well be a DataStage internal format (12 Apr 2007). Try applying an appropriate Oconv() function to get it into the format required in the SQL.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Krazykoolrohit
Charter Member
Charter Member
Posts: 560
Joined: Wed Jul 13, 2005 5:36 am
Location: Ohio

Post by Krazykoolrohit »

ray,

it doesnt accept oconv in SQLs. i have worked it out and made them as a parameter to the jobs. now i need to capture current date and date of a week before in the job parameters.
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

Unless we know what that number exactly signify it will be like hitting in the arrow in the dark.
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
Krazykoolrohit
Charter Member
Charter Member
Posts: 560
Joined: Wed Jul 13, 2005 5:36 am
Location: Ohio

Post by Krazykoolrohit »

ok. lets start from begining. how do i capture yesterdays date and pass into a job using job parameters?
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

currdate()-1 or sysdate()-1 just without even using parameters if you are extracting the data on daily basis.
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
Krazykoolrohit
Charter Member
Charter Member
Posts: 560
Joined: Wed Jul 13, 2005 5:36 am
Location: Ohio

Post by Krazykoolrohit »

now i need to get this sysdate to the following format before passing into the SQL.

Z_PLCMT between '2007-04-06-00.00.00.000000' and '2007-04-12-00.00.00.000000'

so i need systime.or equivalent.
Krazykoolrohit
Charter Member
Charter Member
Posts: 560
Joined: Wed Jul 13, 2005 5:36 am
Location: Ohio

Post by Krazykoolrohit »

us1aslam1us wrote:currdate()-1 or sysdate()-1 just without even using parameters if you are extracting the data on daily basis.


the SQL is aborting when i give the following SQL. i am extracting data from DB2. wud i need to format the sysdate output to DB2 format.

am using this as a filter in the SQL.

Code: Select all

 between sysdate()-1 and sysdate()-5
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The word you were looking for is "would". :x

Since sysdate - 5 is before sysdate - 1 try reversing the order in the BETWEEN constraint.

Also I'm not sure that sysdate is a function. But I'm not in a position to check right now. If it's not, you need to lose the parentheses from it - that is, use SYSDATE rather than SYSDATE().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ds_developer
Premium Member
Premium Member
Posts: 224
Joined: Tue Sep 24, 2002 7:32 am
Location: Denver, CO USA

Post by ds_developer »

I avoid using sysdate in a source query since I am likely to have to reload data for a specific date in the past. I use a job control job to calculate the date then pass it to the real job using DSSetParam. The job control job has a parameter which is normally left blank. This causes the job control code to calculate yesterday's date. When this parameter contains a date (like 20070411) that date is used.

Just an idea.
John
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

For DB2, It should be

Code: Select all

 CURRENT DATE
orelse you can use

Code: Select all

CURRENT TIMESTAMP
Also make about valid date range, typically it
is from 0001-01-01 to 12-31-9999
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Pay attention to ds_develper's suggestion. A very valid point.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Krazykoolrohit
Charter Member
Charter Member
Posts: 560
Joined: Wed Jul 13, 2005 5:36 am
Location: Ohio

Post by Krazykoolrohit »

ds_developer wrote:I avoid using sysdate in a source query since I am likely to have to reload data for a specific date in the past. I use a job control job to calculate the date then pass it to the real job using DSSetParam. The job control job has a parameter which is normally left blank. This causes the job control code to calculate yesterday's date. When this parameter contains a date (like 20070411) that date is used.

Just an idea.
John
Joihn, can you please elaborate? i dont know what the job control parameter should be.
Post Reply