Link to home
Create AccountLog in
Avatar of Cobra967
Cobra967Flag for United States of America

asked on

ODBC error when executing query using MS Access 2013 agaist SQL 2008 using ODBC client 10

Hello I have the statement below that works fine again MS Access table, however it gives me the attached error message when running against a linked ODBC connection to SQL of the same table. How can I fix this? User generated image
SELECT BMPDATA.Battery, Count(BMPDATA.Battery) AS Deployments, Count([NoSample]="Dead Battery") AS Dead
FROM BMPDATA
GROUP BY BMPDATA.Battery;
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

This may have this in mind:

    Sum(Abs([NoSample]="Dead Battery"))

/gustav
That's a syntax error and not an ODBC error.

T-SQL
SELECT Battery, Count(Battery) AS Deployments, Count(CASE[NoSample] WHEN 'Dead Battery' THEN 1 ELSE 0 END) AS Dead
FROM BMPDATA
GROUP BY Battery

Open in new window


I'll not comment on Access SQL, as my skills are a little rusty there.
Avatar of Cobra967

ASKER

Thank you Jim, but the count of dead battery is the same as total deployment which is not correct. I am try to determine how many time a battery was used and how many time the device did not works because the battery was dead. The field NoSample will use have the word Dead Battery when the battery was the cause of no data collection. The code I provided is from MS Access not SQL.
It seems to work in SQL if I use: COUNT(CASE WHEN [NoSample] = 'Dead Battery' THEN 1 ELSE NULL END
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks for the grade.  Good luck with your project.  -Jim