Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sql query

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to find products brought between two dates. The dates are given as
may 2004 to oct 2004

How can I match month and year alone in a select query?

I am using DB2 database.

Select ............from products where
product_purchased_dt btween may 2004 and oct 2004
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use month and year functions.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shan,
Alternatively, use java.util.Calendar to get the beginning of the first month and the end of the last month. You can then pass these two dates to a prepared statement. This may run faster, especially if you have an index on the field.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Shan,
Alternatively, use java.util.Calendar to get the beginning of the first month and the end of the last month. You can then pass these two dates to a prepared statement. This may run faster, especially if you have an index on the field.


this will let your application database independent.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it can be any two months and years
for eg it can be may 2004 to oct 2005 also ...
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shan we are not gettin you i think. is it??
please dont be shy and elaborate it more.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic