Click to See Complete Forum and Search --> : MySQL Syntax Error


slyfox
09-15-2005, 06:05 PM
Hi Peoples

Can anyone tell me what's wrong with this mysql query..?

SELECT item_num, description, status, DATE_FORMAT(date_due, '%c/%e/%Y') as datedue, priority,
IF(current_date() > date_due) THEN 'X' ELSE '' END IF as flag FROM item
WHERE user_id = 3 GROUP BY date_due, description, priority, item_num, status, flag
ORDER BY date_due,priority asc

Here is the error I get:

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 ') THEN 'X' ELSE '' END IF as flag FROM item WHERE user_id = 3 G

Any help please

Thanks

buntine
09-15-2005, 07:57 PM
I'm not sure you can embed an If Statement within a SELECT query.

You might want to just return a boolean or look into a Stored Procedure.

SELECT item_num, description, status, DATE_FORMAT(date_due, '%c/%e/%Y') as datedue, priority, (current_date() > date_due) as flag FROM item
WHERE user_id = 3 GROUP BY date_due, description, priority, item_num, status, flag
ORDER BY date_due,priority asc

Regards.

slyfox
09-16-2005, 04:17 AM
You can:

http://dev.mysql.com/doc/mysql/en/if-statement.html