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 error:
Operand data type bit is invalid for sum operator.
SELECT SUM(CAST(bitColumn AS INT))
FROM dbo.MyTable
need to cast into number
or another solution -
SELECT COUNT(*)
FROM dbo.MyTable
WHERE bitColumn = 1