Any Better Ways To Ascertain Whether A Column In A Table Is Empty Or Not?

- 1 answer

I have a table say T in SQL Server 2005 database and it has two columns say A and B, which more often than not won't have any values in them. How to check whether A and B are empty (has all zero length strings) or not?

I have this naive way of doing it -

select count(*) as A_count from T where A <> ''

Let's assume A has data type varchar.

I was wondering whether I can get the same information using a system table, and if so would that be faster than this query?




If your column is nullable, you will have to modify your query as follows:

select count(*) as A_count from T where COALESCE(A, '') <> ''

otherwise you will not count nulls.