

NULLs don’t really matter here because we aren’t counting any particular column. Here we are counting the number of rows in the table. Essentially the count tag resolves to a number equal to how many times a loop with identical attributes would iterate. The count tag shares all attributes of loop-start tag. It allows a template to show the number of elements on any object type within the current context. Count the number of rows SELECT COUNT(*) FROM TableName The count tag was introduced in ESS 8.1.0. Really this is the same as the regular COUNT (warnings, nulls etc) with the one exception that, currently at least, you can’t use windowing functions with COUNT DISTINCT. Using the same list of values, (1, NULL, 1, 2, 3, NULL, 1), this time you’ll get 3. Here we get the number of DISTINCT non NULL values. Count the distinct number of values SELECT COUNT(DISTINCT FieldName) FROM TableName Warning: NULL value is eliminated by an aggregate or other SET operation. You do get a nice warning (depending on your ANSI_WARNINGS setting) if there was a NULL value though.

So in a column with (1, NULL, 1, 2, 3, NULL, 1) you’ll get a count of 5. Here you are counting the number of non NULL values in FieldName. The ALL argument is the default and is unnecessary (I didn’t even know it existed until I started this post). SELECT COUNT(ALL FieldName) FROM TableName

Here are three different ways to COUNT: Count the number of values SELECT COUNT(FieldName) FROM TableName How do NULL values affect the COUNT function? As always I enjoy these quizzes and in this particular case it gave me an idea for a post. Specifically the Quiz: COUNT() in SQL Server. Recently I was doing one of Kendra Little’s ( b/ t) SQL Server quizzes.
