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 

Fetch first few bytes from an Integer field

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


Joined: 27 Feb 2007
Posts: 10
Topics: 5
Location: India

PostPosted: Fri Aug 08, 2008 12:32 am    Post subject: Fetch first few bytes from an Integer field Reply with quote

Hi,

I have an integer field in my table where I store the date in YYYYMMDD format. I have a requirement now to fetch the rows that falls on a particular year and particular month. The month field however is not mandatory.
I am thinking putting a query which uses BETWEEN YYYYMM01 and YYYYMM31.
I am curious to know is there any other way to achieve the same result.

Again, I couldnt find out whether this has been already posted.
Please forgive if already posted
_________________
Rgds,
Balaji
Back to top
View user's profile Send private message Yahoo Messenger
shantharam_k
Beginner


Joined: 03 Feb 2007
Posts: 4
Topics: 0

PostPosted: Fri Aug 08, 2008 2:21 am    Post subject: Reply with quote

Using BETWEEN is probably the best bet for you.

However, any idea on why the filed is defined as INT? There is no gain in terms of space as both use 4 bytes. And u need to carry the extra overhead of validating the data before insertion (for ex. you can insert a value of 20080230 into this INT fileld which would fail if it were a DATE). Also take caution before insertion of data so that leading zeroes in the MM and DD fields are not lost. Else you may end up with catastrophic results. Shocked
Back to top
View user's profile Send private message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Mon Aug 11, 2008 9:18 am    Post subject: Reply with quote

Balaji, you could use YEAR and MONTH scalar functions. However, they depreciate the performance of your query is it is too critical. otherwise, that should give you hte results.

select * from table where year(column1) = 2000 and month(column1) = 01
_________________
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: Mon Aug 11, 2008 10:34 am    Post subject: Reply with quote

seekaysk wrote:
Balaji, you could use YEAR and MONTH scalar functions. However, they depreciate the performance of your query is it is too critical. otherwise, that should give you hte results.

select * from table where year(column1) = 2000 and month(column1) = 01


YEAR and MONTH only work with columns defined as DATE or TIMESTAMP!
Back to top
View user's profile Send private message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Mon Aug 11, 2008 12:07 pm    Post subject: Reply with quote

oh, my apologies. i might have not read the complete req. now I get ti's an INT column.
_________________
Thanks.
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