tsql - Conversion error using CASE on a varchar column -


i'm trying grab information send google charts graph i'm looking @ column active can true/false set varchar in database.

using query:

select     sum(case when convert(int, active) active = 1 1 else 0 end) active,     sum(case when convert(int, active) active = 0 1 else 0 end) inactive      events 

throws error:

conversion failed when converting varchar value 'true' data type int.`

ints not booleans.... called bit in sql server. try;

select sum(case when convert(bit, active) = 1 1 else 0 end) active, sum(case when convert(bit, active) = 0 1 else 0 end) inactive events 

or test string

select sum(case when active = 'true' 1 else 0 end) active, sum(case when active = 'false' 1 else 0 end) inactive events 

p.s. storing boolean values string columns silly... consider changing column bit column don't need convert it


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -