I am having a problem using multiple And‘s in a Case statement.
My Database looks like:
Enrollment Paperless Validated
0 1 0
1 0 1
0 1 0
1 1 1
0 0 0
0 1 0
0 0 0
0 1 0
1 1 1
0 1 0
So my query looks like this:
Select
Count(case when [Enrollment] = 1 and [Paperless] = 1 and [Validated] = 1 then 1 else 0 end) as [Paperless]
,Count(case when [Enrollment] = 1 and [Paperless] = 1 and [Validated] = 1 then 1 else 0 end) as [Online_Only]
,Count(*) as "Total"
FROM [my_table]
Sql Fiddle: http://sqlfiddle.com/#!3/61202/5
As you can see from the sql fiddle the count is always 20 in the case statements when they should be different. Am I just doing something wrong in my case statement or do i have to do them in sub-queries?
Dave
COUNTreturns true regardless of the actual value. So use:instead of