Avatar of Cobra967
Cobra967
Flag 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? Error message
SELECT BMPDATA.Battery, Count(BMPDATA.Battery) AS Deployments, Count([NoSample]="Dead Battery") AS Dead
FROM BMPDATA
GROUP BY BMPDATA.Battery;
Microsoft AccessMicrosoft SQL Server

Avatar of undefined
Last Comment
Jim Horn

8/22/2022 - Mon
Gustav Brock

This may have this in mind:

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

/gustav
Jim Horn

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.
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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Cobra967

ASKER
It seems to work in SQL if I use: COUNT(CASE WHEN [NoSample] = 'Dead Battery' THEN 1 ELSE NULL END
ASKER CERTIFIED SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jim Horn

Thanks for the grade.  Good luck with your project.  -Jim