Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

correct mySQL syntax?

Status
Not open for further replies.

dunce

Programmer
Jan 5, 2001
2
0
0
GB
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
 
You can try replacing # with '. If I'm not mistaken the # delimiter is used in Access databases only.
 
What exactly are you trying to accomplish with the &quot;#&quot;? 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.
 
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top