File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Sql query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Sql query" Watch "Sql query" New topic
Author

Sql query

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Aug 04, 2004
Posts: 724
Use month and year functions.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31074
    
232

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Nov 22, 2008
Posts: 18944
it can be any two months and years
for eg it can be may 2004 to oct 2005 also ...
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Shan we are not gettin you i think. is it??
please dont be shy and elaborate it more.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sql query