Yesterday's date as 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

Post Reply
DSer
Participant
Posts: 9
Joined: Thu Nov 09, 2006 11:53 pm

Yesterday's date as parameter

Post by DSer »

Hello everybody

My database is Oracle.
I have a table which has a date column.
I want to query against it to get data for yesterday's date, which is already available in the table.
I can do this using an oracle query, but I need a way to pass yesterday's date as a parameter to a SQL query in Oracle OCI stage.
How do I go about doing this?
thebird
Participant
Posts: 254
Joined: Thu Jan 06, 2005 12:11 am
Location: India
Contact:

Post by thebird »

Define a parameter for the Date in the job - and use it in the User Defined SQL query. Pass it down to the job through the Sequence.

In the Sequence, use a User variable activity to come up with the value for Yesterday's date - from Current Date (Sysdate).

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

Post by chulett »

You can certainly do it via a number of methods, but why not use TRUNC(SYSDATE-1) in your query instead if it always needs to be 'yesterday'?
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSer
Participant
Posts: 9
Joined: Thu Nov 09, 2006 11:53 pm

Post by DSer »

The date can change sometimes, that is the reason why i want to parameterise it.
Craig, Can I use TRUNC(SYSDATE-1) as a parameter value?
How do i give the default value of the parameter as yesterday's date?
If the date changes i should be able to give another date.
thebird
Participant
Posts: 254
Joined: Thu Jan 06, 2005 12:11 am
Location: India
Contact:

Post by thebird »

DSer wrote:The date can change sometimes, that is the reason why i want to parameterise it.
Craig, Can I use TRUNC(SYSDATE-1) as a parameter value?
How do i give the default value of the parameter as yesterday's date?
If the date changes i should be able to give another date.
In that case, instead of the date, why dont you parameterize the number of days (from the SYSDATE)?

Using Craig's method you can put it in as

Code: Select all

TRUNC(SYSDATE-#NumDays#)
in the query.

Aneesh[/code]
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or you could parameterize that entire portion of the query:

Code: Select all

AND DATE_FIELD = #P_DATE_CLAUSE#
Default the value to TRUNC(SYSDATE-1) so that 'normal' runs compute yesterdays date from the current system date. Override the value if need be by passing in a fixed date:

TO_DATE('12/01/2006','MM/DD/YYYY')

Would be one way to do that. Or you could even include the operator in the parameter value so that you could even pass the query an 'in list' of dates or a 'between' to do date ranges. This rather than being "stuck" with it always being an equality check.

All kinds of solutions are available to you. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSer
Participant
Posts: 9
Joined: Thu Nov 09, 2006 11:53 pm

Post by DSer »

Nice replies craig and thebird.
Craig, do i need to pass TO_DATE('12/01/2006','MM/DD/YYYY') if i have to override? is there no way i can pass just 12/01/2006 or 12-01-2006
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not if you want the flexibility. TO_DATE in Oracle is like IConv in DataStage and gets you an 'internal' date that can be directly compared to another DATE field without issue. Once you start comparing strings you can cause yourself all kinds of grief.

While there are ways you can 'cheat' and just pass in a date as a string, best if you learn proper syntax that you know will always work no matter who's instance you connect to. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSer
Participant
Posts: 9
Joined: Thu Nov 09, 2006 11:53 pm

Post by DSer »

Makes sense, Thanks Craig
Post Reply