davidjwest
davidjwest

Reputation: 546

Access Count of Rows Where Field is not Null

I need to count rows where the value of Master.[Date BP] is not Null - any ideas how I would do this?

I tried this but it doesn't seem to work.

SELECT Master.[Date BP], Count(Master.[Date BP]) AS CountOfField,
FROM Master
GROUP BY Master.[Date BP];

Upvotes: 2

Views: 869

Answers (3)

Tim Ng
Tim Ng

Reputation: 1

The above answers are correct. Just in case you may face other problems with other aggregate functions, aggregate functions in SQL will ignore the null value.

Reference: https://msdn.microsoft.com/en-us/library/ms173454.aspx

Upvotes: 0

Mureinik
Mureinik

Reputation: 311338

Using count is the right idea. You just need to remove the group by clause, as you want a single answer. Additionally, you have a redundant comma at the end of the select list:

SELECT Count(Master.[Date BP]) AS CountOfField
FROM   Master

Upvotes: 2

juergen d
juergen d

Reputation: 204766

SELECT Count([Date BP]) AS CountOfField
FROM Master

Upvotes: 2

Related Questions