Solved

MySQL Between Dates Problem...

Posted on 2010-09-07
3
346 Views
Last Modified: 2012-05-10
Hey Guys and Gals,
I am having an issue with an SQL string.  I am trying to pull some results from my MySQL database that will be between a set of dates given by the user.

I have attached my SQL string...

Also, the date field in my MySQL DB is a DATE field, not a DATETIME.

Any help would be appreciated!
"SELECT cancelStatus, orderDate, delTelephone, invTelephone, orderDate, invName, emailaddress, ordertotal, ocCusEmail FROM malsinfo WHERE ocCusEmail = '" & sessionName & "' AND orderDate BETWEEN  = " & startDate & " AND " & endDate & ""

Open in new window

0
Comment
Question by:Slim81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 33621194
It looks like you are missing ' (single quotes)

 "SELECT cancelStatus, orderDate, delTelephone, invTelephone, orderDate, invName, emailaddress, ordertotal, ocCusEmail FROM malsinfo WHERE ocCusEmail = '" & sessionName & "' AND orderDate BETWEEN  = '" & startDate & "'  AND  '" & endDate & "' " 
0
 
LVL 4

Author Comment

by:Slim81
ID: 33621788
Thanks for the advice sammy, I actually started with the single quotes but removed them to see if that was the problem.

I am still getting the same error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '2010-09-01' AND '2010-09-07'' at line 1
0
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 33623815
hi Slim81

The error is correct because there is a "=" near between. Please remove it.

It should be this:

"SELECT cancelStatus, orderDate, delTelephone, invTelephone, orderDate, invName, emailaddress, ordertotal, ocCusEmail FROM malsinfo WHERE ocCusEmail = '" & sessionName & "' AND orderDate BETWEEN  '" & startDate & "'  AND  '" & endDate & "' "
0

Featured Post

Webinar: Choosing a MySQL HA Solution

Join Percona’s Principal Technical Services Engineer, Marcos Albe as he presents Choosing a MySQL High Availability Solution on Thursday, June 29, 2017 at 10:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question