Can Count(*) ever return null?

14,077

Solution 1

No, it will only return a zero (or non-zero) result. SqlServer will not return null.

Solution 2

According to the MSDN page, no.

That said:

For return values greater than 2^31-1, COUNT produces an error. Use COUNT_BIG instead.

Solution 3

No.

This will be 0

select count(*)
where 0=1

This will be 1

select count(*)

Solution 4

No it returns a zero if the table does not have any records in the table

Solution 5

No. If the table or specific field being counted are empty it will return zero.

Share:
14,077
m.edmondson
Author by

m.edmondson

Many of my best answers are written up fully and ported to my blog. This (along with my other abstract ideas) allows me to create an online portfolio of important and interesting information for both referencing and for others to learn from. View my LinkedIn Profile.

Updated on June 18, 2022

Comments