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 

Using concat & substr

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


Joined: 08 Sep 2007
Posts: 86
Topics: 27

PostPosted: Mon Dec 05, 2011 7:44 am    Post subject: Using concat & substr Reply with quote

I need to run a query like this:
Code:

Select tab_number
         ,tab_name
from tab
where date(tab_timestamp) >= tab_rec_date;

In this situation tab_rec_date is length of 8 bytes (YYYYMMDD) and
date(tab_timestamp) is length of 10 bytes (YYYY-MM-DD).

I tried to do this
Code:

where date(tab_timestamp) >= substr(tab_rec_date,1,4) ||
                                              substr(tab_rec_date,5,2) ||
                                              substr(tab_rec_date,7,2)

But I got an error msg:
Code:

DSNT408I SQLCODE = -104, ERROR:  ILLEGAL SYMBOL "(". SOME SYMBOLS THAT MIGHT
         BE LEGAL ARE: , FROM INTO                                           
DSNT418I SQLSTATE   = 42601 SQLSTATE RETURN CODE                             
DSNT415I SQLERRP    = DSNHPARS SQL PROCEDURE DETECTING ERROR                 
DSNT416I SQLERRD    = 502 0  0  -1  599  0 SQL DIAGNOSTIC INFORMATION       
DSNT416I SQLERRD    = X'000001F6'  X'00000000'  X'00000000'  X'FFFFFFFF'     
         X'00000257'  X'00000000' SQL DIAGNOSTIC INFORMATION                 

Can someone help me?

thanks a lot
_________________
The more I learn, the more I want to learn.
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Mon Dec 05, 2011 11:00 am    Post subject: Reply with quote

Try this(I did not test)
Code:

where date(tab_timestamp) >=
DATE(substr(tab_rec_date,1,4) || '-' ||
substr(tab_rec_date,5,2) || '-' ||
substr(tab_rec_date,7,2) )

_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Dec 05, 2011 12:03 pm    Post subject: Reply with quote

prog_mario,

I am assuming you did not show us the complete SQL as your error messages indicate you have an error on the INTO statement.

Either way your comparison is flipped. Shouldn't you be using the substr on tab_timestamp? or you need to concatenate the '-' to the tab_rec_date like nascar has shown.

Here is an alternative way of comparing (Untested )

Code:

WHERE REPLACE(DATE(tab_timestamp),'-','') >= tab_rec_date;


Modified sql from this topic

http://www.mvsforums.com/helpboards/viewtopic.php?t=11000&highlight=replace

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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