locked
Count check boxes RRS feed

  • Question

  • User1028962535 posted

    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

    SELECT Location,datename(month,Timestamp1)as [Month]
    ,SUM(Case when  Error1='True' then 1 else 0 end) + SUM(Case when  Error2='True' then 1 else 0 end) + SUM(Case when  Error3='True' then 1 else 0 end) 
    AS Error FROM dbo.Errors GROUP BY datename(month,timestamp1),Location

    Sunday, June 14, 2020 10:48 AM

All replies

  • User452040443 posted

    Hi,

    What is the exact problem of your query? What's not working?

    Sunday, June 14, 2020 6:38 PM
  • User1028962535 posted

    Apologies, there was a typo in my initial SQL, the SQL statement works fine

    Sunday, June 14, 2020 7:52 PM