I have one table, that captures the location and month as well as several error type represented as check boxes. I would like to SUM the number of errors each month based on location, but I am not sure on how to write the SQL
Table looks like this should look like this:
Month Location ErrorType1 ErrorTpye2 ErrorType3
May LOC1 4 7 20
May LOC2 5 12 3
June LOC1 23 3 55
I would like the query result to sum the error types, and produce a result like
Month Location Error
May LOC1 31 (SUM ALL ERROR TYPES)
May LOC2 20
June LOC1 81
I tried something list this,but its not working..any ideas please..thanks
SELECT Location,datename(month,Timestamp1)as[Month],SUM(Casewhen Error1='True'then1else0end) + SUM(Casewhen Error2='True'then1else0end) + SUM(Casewhen Error3='True'then1else0end) AS Error
FROM dbo.Errors
GROUPBY datename(month,timestamp1),Location
Member
64 Points
262 Posts
Count check boxes
Jun 14, 2020 10:48 AM|Dan5|LINK
Hello,
I have one table, that captures the location and month as well as several error type represented as check boxes. I would like to SUM the number of errors each month based on location, but I am not sure on how to write the SQL
Table looks like this should look like this:
Month Location ErrorType1 ErrorTpye2 ErrorType3
May LOC1 4 7 20
May LOC2 5 12 3
June LOC1 23 3 55
I would like the query result to sum the error types, and produce a result like
Month Location Error
May LOC1 31 (SUM ALL ERROR TYPES)
May LOC2 20
June LOC1 81
I tried something list this,but its not working..any ideas please..thanks
Participant
1130 Points
299 Posts
Re: Count check boxes
Jun 14, 2020 06:38 PM|imapsp|LINK
Hi,
What is the exact problem of your query? What's not working?
Member
64 Points
262 Posts
Re: Count check boxes
Jun 14, 2020 07:52 PM|Dan5|LINK
Apologies, there was a typo in my initial SQL, the SQL statement works fine