aspose file tools*
The moose likes JDBC and the fly likes the between clause Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "the between clause" Watch "the between clause" New topic
Author

the between clause

Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 150
Hi all,

My am getting an error for the following mysql syntax



Error:

right syntax to use near 'mydate BETWEEN 20091226 AND 20091226 GROUP BY item_name' at line 1

Thank you in advance
Praveen Rajendran
Greenhorn

Joined: Dec 25, 2009
Posts: 21
Hi,

I guess the problem is you missed an AND between the where clauses salesman and mydate.

select item_name,SUM(qty),SUM(total_amt) from invoice where salesman=? mydate BETWEEN ? AND ? GROUP BY item_name"


I guess the below code would work.. let me know..

select item_name,SUM(qty),SUM(total_amt) from invoice where salesman=? and mydate BETWEEN ? AND ? GROUP BY item_name


Thanks & Regards,
Praveen
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

For purposes of creating more-standard SQL queries I recommend you replace "X BETWEEN Y AND Z" syntax with "X > Y AND X < Z". At the very least it gives you better control over inclusive (<=,>=) searches as well as creates code that works better on more systems. Least of which, I find the syntax of both to be similar. Anyone have reasons for strongly recommend ever using the keyword BETWEEN?


My Blog: Down Home Country Coding with Scott Selikoff
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

Behaviour of BETWEEN is vendor specific.It might pick only the values in between the boundary values provided or includes both boundary values as well or .... BETWEEN


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 150
Thank you all for those replies.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the between clause