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

What is happening when Matlab is starting a "parallel pool"? -

php - Cannot override Laravel Spark authentication with own implementation -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -