IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Date Arithmetic with String obtained with SELECT


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
henriquecosta

New User


Joined: 06 Jan 2010
Posts: 9
Location: Lisbon, Portugal

PostPosted: Fri Mar 12, 2010 8:21 pm
Reply with quote

Hello,

I need to build a query to use in an UNLOAD that fetches all registers with timestamp older than X days old, where X is a CHAR variable in one of our tables.

Is this possible? I have been trying:

WHERE TS_field < CURRENT_DATE -
(SELECT X_Char_Field
from PARAM_TABLE
where pk = 'yaddayadda') DAYS

I have also tried with (...) CURRENT_DATE - DEC(SELECT (...), but I keep getting syntax errors.

Can anywone recommend a way to do this?

Thanks,
Henrique
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Mar 12, 2010 9:17 pm
Reply with quote

Code:
...WHERE TS_field < CURRENT_DATE -
(SELECT integer(X_Char_Field)
from PARAM_TABLE
where pk = 'yaddayadda') DAYS


Manual wrote:
The result is the same number that would result from CAST(string-expression
AS INTEGER). Leading and trailing blanks are eliminated and the resulting
string must conform to the rules for forming an integer constant. If the whole
part of the argument is not within the range of integers, an error is returned.
Back to top
View user's profile Send private message
henriquecosta

New User


Joined: 06 Jan 2010
Posts: 9
Location: Lisbon, Portugal

PostPosted: Fri Mar 12, 2010 9:30 pm
Reply with quote

Hi,

Worked great, thanks!!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top