CalvT CalvT - 6 months ago 9
SQL Question

MySQL Query Select Current Month Error

I built the following query using ms access.

SELECT GVA14.COD_VENDED, Count(GVA14.RAZON_SOCI) AS CountOfRAZON_SOCI
FROM GVA14
GROUP BY GVA14.COD_VENDED, Year([FECHA_ALTA]), Month([FECHA_ALTA])
HAVING (((Year([FECHA_ALTA]))=Year(curDate())) AND
((Month([FECHA_ALTA]))=Month(curDate())));


The error is


[Err] 1064 - 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 '[FECHA_ALTA]), Month([FECHA_ALTA])


I changed the "date" to "curdate" to comply with MySQL but it still comes up with an error.

Thanks

Answer

Fixed with this query from Leandro Barreto

SELECT GVA14.COD_VENDED, GVA14.RAZON_SOCI, GVA14.FECHA_ALTA
FROM GVA14
WHERE Month(GVA14.FECHA_ALTA)=Month(curDate())
and Year(GVA14.FECHA_ALTA)=Year(curDate())
GROUP BY GVA14.COD_VENDED, GVA14.RAZON_SOCI, GVA14.FECHA_ALTA
Comments