Ash Machine Ash Machine - 1 year ago 150
SQL Question

SQL : How to sum multiple bit columns in a row

I have a data structure that has repeating bit columns per row

enter image description here

How to I get the total number of Trues for each row? For example

Id Total

03 2

17 0

21 3

24 2

Answer Source

Cast the bit to Int and do the arithmetic operation

select id,cast([Ok_1112] as Int)+cast([Ok_1213] as Int)+...
From yourtable
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download