Any function to subtract 1month from the given date

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
ravij
Premium Member
Premium Member
Posts: 170
Joined: Mon Oct 10, 2005 7:04 am
Location: India

Any function to subtract 1month from the given date

Post by ravij »

Hi,

I am passing the business date through parameter to retrieve the data from DB2 db. Now I need to subtract 1month from the date(format is like YYYYMM, Ex: 200701).

Is there any way to calculate the above one?

Thanks in advance.
Ravi
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Yes.

Does not the Search menu option work for you?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ravij
Premium Member
Premium Member
Posts: 170
Joined: Mon Oct 10, 2005 7:04 am
Location: India

Post by ravij »

Sorry Ray, I searched in the forum but I could not find any help in search... Please help me to solve this issue.

I appreciate your help
Ravi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I tried searching for something silly - 'subtract month' - and easily found what you were looking for. You may still need to branch out from there as your definition of what 'one month' is can change the answer.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ravij
Premium Member
Premium Member
Posts: 170
Joined: Mon Oct 10, 2005 7:04 am
Location: India

Post by ravij »

Hi,

Actually I need to subtract one month from the date parameter(business date ex: YYYYMM or 200702) in WHERE clause in DB2 stage. We have written USER DEFINED SQL in the db2 stage.

The code is like:
WHERE ACG_CGY_CODE in ('31520001', '31520002') and DOC_TP = 'SV' and MSR_PRD_ID = <business date YYYYMM> - 1
Please help to solve this issue.
Thanks in advance
Ravi
ravij
Premium Member
Premium Member
Posts: 170
Joined: Mon Oct 10, 2005 7:04 am
Location: India

Post by ravij »

Hi,

Actually I need to subtract one month from the date parameter(business date ex: YYYYMM or 200702) in WHERE clause in DB2 stage. We have written USER DEFINED SQL in the db2 stage.

The code is like:
WHERE ACG_CGY_CODE in ('31520001', '31520002') and DOC_TP = 'SV' and MSR_PRD_ID = <business date YYYYMM> - 1
Please help to solve this issue.
Thanks in advance
Ravi
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've made it a DB2 question - surely you should be asking it in a DB2 forum somewhere. There is a perfectly good AddMonths routine available here but, no, you want to do it in SQL. Fine, go for it: it's no longer a DataStage question.
Last edited by ray.wurlod on Sun Dec 02, 2007 10:26 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You don't need to do the subtraction in the SQL, although I'm sure that can be done. The routines you can find here would allow you to subtract a month from the parameter before it is passed to the job.

Ask your DBA how to do that in DB2 SQL.
-craig

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