This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sql query  RSS feed

 
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
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use month and year functions.
 
author & internet detective
Marshal
Posts: 37714
579
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.
 
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
Boost this thread!