Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 count and case

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2010-08-26 : 09:04:32

Objective:
Counting the number of records in the Audit_JobNC with a periodkey of 61

I am using the following:
select count(CASE when PeriodKey = '61') from Audit_JobNC

But receive this:
Incorrect syntax near ')'.


Thank you for your help
T

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-26 : 09:10:48
select count(*) from Audit_JobNC WHERE PeriodKey = '61'


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-26 : 09:11:22
select SUM(CASE WHEN PeriodKey = '61' THEN 1 ELSE 0 END) from Audit_JobNC



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

tariq2
Posting Yak Master

125 Posts

Posted - 2010-08-26 : 09:54:27
thank you, very helpful
Go to Top of Page
   

- Advertisement -