• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

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;
0
Cobra967
Asked:
Cobra967
  • 3
  • 2
1 Solution
 
Gustav BrockCIOCommented:
This may have this in mind:

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

/gustav
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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.
0
 
Cobra967Author Commented:
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.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Cobra967Author Commented:
It seems to work in SQL if I use: COUNT(CASE WHEN [NoSample] = 'Dead Battery' THEN 1 ELSE NULL END
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Typo in my first post,Count should have been Sum
SELECT Battery, Count(Battery) AS Deployments, Sum(CASE[NoSample] WHEN 'Dead Battery' THEN 1 ELSE 0 END) AS Dead
FROM BMPDATA
GROUP BY Battery

Open in new window


>It seems to work in SQL if I use: COUNT(CASE WHEN [NoSample] = 'Dead Battery' THEN 1 ELSE NULL END
S'pose it would, as it's not counting NULLs..
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now