PDA

View Full Version : What's wrong with this query?


Lea Verou
10-15-2005, 08:38 AM
Can anyone point me to the right direction in what's wrong with the query below? The query is supposed to be in a plugin that displays the average age in forumhome (not mine), but it gives a database error:


SELECT ROUND(AVG(YEAR(NOW())-YEAR(birthday_search) - (MONTH(NOW()) < MONTH(birthday_search)) - (MONTH(NOW()) = MONTH(birthday_search) AND DAY(NOW()) < DAY(birthday_search)))) AS avgage FROM " . TABLE_PREFIX . " user WHERE YEAR(birthday_search)>0

nexialys
10-15-2005, 11:02 AM
you simply have a space here: " . TABLE_PREFIX . " user ...<< between the " and user...

Lea Verou
10-15-2005, 11:10 AM
Thanks a lot. I'll try although I don't think this is the error cause in the database error I get, the table has the name it should have so the name is built correctly.

edit: Yep, I was correct, that didn't fix the problem :(

Paul M
10-15-2005, 11:13 AM
It might help if you actually posted the error.

Lea Verou
10-15-2005, 11:26 AM
Woops sorry!
The error I get is:
atabase error in vBulletin 3.5.0:

Invalid SQL:
SELECT ROUND(AVG(YEAR(NOW())-YEAR(birthday_search) - (MONTH(NOW()) < MONTH(birthday_search)) - (MONTH(NOW()) = MONTH(birthday_search) AND DAY(NOW()) < DAY(birthday_search)))) AS avgage FROM testvb_user WHERE YEAR(birthday_search)>0;

MySQL 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 '(NOW()) < DAY(birthday_search)))) AS avgage FROM testvb_user WH
Error Number : 1064