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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -