SQL Flow Field Guide

COUNT

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

aggregation

What changes

Input
the argument expression over each group's rows (COUNT(*) reads no column)
Output or change
one value per group (or one for the whole input when there is no GROUP BY)
Return type
Returns int NOT NULL when ANSI_WARNINGS is ON. However, SQL Server always treats COUNT expressions as int NULL in metadata, unless wrapped in ISNULL. Returns int NULL when ANSI_WARNINGS is OFF.

Syntax at a glance

COUNT ( { [ [ ALL | DISTINCT ] expression ] | * } )

Work example

Count input rows when a report needs a total, including rows whose columns are null.

Compare COUNT(*) with COUNT(amount) on rows that include a null amount.

Check your work COUNT(column) skips null values, while COUNT(*) counts each row.

Practice SQL

Open in SQL Flow
SELECT COUNT(*) AS row_count, COUNT(amount) AS known_amounts FROM (VALUES (10), (NULL), (30)) AS v(amount);

Open Microsoft Learn for full syntax, permissions, and details for your version.