DAN212 DAN212 - 2 years ago 93
SQL Question

SQL - Syntax error (missing operator) in query expression 'SUM(Cost) "Total Cost"'

I can't figure this out. I have used the command below in phpmyadmin with no problems but I create my database in Microsoft Access and suddenly the query has a syntax error. I've checked it over and over and I get the same answer everytime. What am I doing wrong?

SELECT vet_id, Visit_date, SUM(Cost) "Total Cost" FROM medication
GROUP BY vet_id, Visit_date;

Answer Source
SELECT vet_id, Visit_date, SUM(Cost) AS [Total Cost]
FROM medication
GROUP BY vet_id, Visit_date;

Access requires you to include the AS keyword when you alias a field expression.

I enclosed the alias in square brackets. If you use quotes instead ... AS "Total Cost" ... Access will include those quotes in the column header.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download