MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Use of variable in Date functions

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Fri Apr 11, 2008 9:12 am    Post subject: Use of variable in Date functions Reply with quote

Hi,

I am using a date function and need to calculate 5 or 10 years before the date depending on some value.

Can I use below code ?

Code:
if value = 0
   move 10 to WS-ADJUSTED-DATE
else
   move 5 to WS-ADJUSTED DATE
end-if

SELECT DATE(MIN(PM_ME_DATE)) - :WS-ADJUSTED-DATE
FROM TABLE


or do i need to write the above sql query two times under if-endif (one for 5 years and other for 10 years).

thanks.
_________________
Thanks.
Back to top
View user's profile Send private message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Fri Apr 11, 2008 9:24 am    Post subject: Reply with quote

seekaysk wrote:
Hi,

I am using a date function and need to calculate 5 or 10 years before the date depending on some value.

Can I use below code ?

Code:
if value = 0
   move 10 to WS-ADJUSTED-DATE
else
   move 5 to WS-ADJUSTED DATE
end-if

SELECT DATE(MIN(PM_ME_DATE)) - :WS-ADJUSTED-DATE
FROM TABLE


or do i need to write the above sql query two times under if-endif (one for 5 years and other for 10 years).

thanks.
Quote:

SELECT DATE(MIN(PM_ME_DATE)) - :WS-ADJUSTED-DATE
FROM TABLE


I am sorry. The query should be:

Code:

SELECT DATE(MIN(PM_ME_DATE)) - :WS-ADJUSTED-DATE  YEARS
FROM TABLE


Is it a correct query ?
_________________
Thanks.
Back to top
View user's profile Send private message
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Fri Apr 11, 2008 9:36 am    Post subject: Reply with quote

several options:
1. dynamical SQL - prepare SQL first
2. if - then, different stastic SQLs
3. get the column first, do calculation in your progrom
....
Back to top
View user's profile Send private message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Fri Apr 11, 2008 11:18 am    Post subject: Reply with quote

hmm...well looks I will have to do a longer way. if-then, different static sqls.

thanks videlord.
_________________
Thanks.
Back to top
View user's profile Send private message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Fri Apr 11, 2008 12:11 pm    Post subject: Reply with quote

videlord wrote:
several options:
1. dynamical SQL - prepare SQL first
2. if - then, different stastic SQLs
3. get the column first, do calculation in your progrom
....


NO. Please stick with things you know


SELECT DATE(MIN(PM_ME_DATE)) - :WS-ADJUSTED-DATE
FROM TABLE

Just add the into clause and if ws-adjusted-date is defined correctly it will work.
Back to top
View user's profile Send private message
haatvedt
Beginner


Joined: 14 Nov 2003
Posts: 66
Topics: 0
Location: St Cloud, Minnesota USA

PostPosted: Sun Apr 13, 2008 11:45 pm    Post subject: Reply with quote

seekaysk,

another option may be to just select the minimum date. Move it to a redefined work area so that you can reference the CCYY field as a PIC 9(4) value and then subtract the appropriate number of years from the redefined CCYY field.

SELECT MIN(PM_ME_DATE)
FROM TABLE


good luck.
_________________
Chuck Haatvedt

email --> clastnameatcharterdotnet

(replace lastname, at, dot with appropriate
characters)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group