How can I use SUM for bit columns?

前端 未结 7 1073
栀梦
栀梦 2021-01-01 10:45

How can use the function SUM() for bit columns in T-SQL?

When I try do it as below:

SELECT SUM(bitColumn) FROM MyTable;

I get the e

7条回答
  •  -上瘾入骨i
    2021-01-01 11:01

    SELECT SUM(bitColumn * 1) FROM dbo.MyTable
    

    Converts the bit into int, by multiplication, clean and simple

提交回复
热议问题