×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

correct mySQL syntax?

correct mySQL syntax?

correct mySQL syntax?

(OP)
Can anyone PLEASE help with the correct syntax for this sql statement?
It works fine in Access and gives the desired results but i cannot make it work with mySQL. The table is fine, i have checked field names etc...but it will not run

SELECT Count(PageUrl)AS PageCount, PageUrl as URL FROM tbltracker WHERE HitDateTime >= #01/01/2001# AND HitDateTime <= #06/01/2001# AND id='biz' GROUP BY PageUrl ORDER BY Count(PageUrl) DESC

MySQL said: You have an error in your SQL syntax near '' at line 1


Many Thanks
Mark Baxter UK

RE: correct mySQL syntax?

You can try replacing # with '. If I'm not mistaken the # delimiter is used in Access databases only.

RE: correct mySQL syntax?

What exactly are you trying to accomplish with the "#"? I don't think MySQL uses those anywhere. You should just enclose your values with '.

If you are trying to make MySQL recognize a date format such as __/__/____, you are out of luck. The > and < signs will do nothing for you here, because MySQL is just reading those fields as plain text. You need to read about how MySQL handles dates, if you want it to do native date matching. Or you will have to do something else programmatically to handle your date format.

Actually, here is third thing you can do if you really don't want to mess with the above:

1. Split dates into 3 columns: month, day, and year

2. Make these columns numeric. Month and day should be TINYINT, while Year should be SMALLINT.

3. You will have to do more complex SQL statements, but your > and < operators will now work.

RE: correct mySQL syntax?

Alternatively Mark, you can replace your query on the date with:

SELECT Count(PageUrl) AS PageCount, PageUrl AS URL FROM tbltracker WHERE HitDateTime BETWEEN '2001-01-01' AND '2001-01-06'AND id='biz' GROUP BY PageUrl ORDER BY Count(PageUrl) DESC

MySQL date format is yyyy-mm-dd

I'm assuming HitDateTime is a table field. If so, you need to call this within your SELECT statement.

RE: correct mySQL syntax?

(OP)
Thanks for that guys....a bit of a shock as i posted this over two months ago...but thanks anyway.

I actually managed it in the end by using the method suggested by eddiebt {BETWEEN}.
The reason I used the # sign was that I was familiar with access at the time...whilst mySQL dosen't use this delimiter, it doesn't mind if you do....go figure.

thanks again

Mark Baxter

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close