SQL Flow Field Guide

VAR

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
float

Syntax at a glance

VAR ( [ ALL | DISTINCT ] expression )

Work example

Estimate variance for a numeric sample.

Try null-only, duplicate, and one-row groups. Check result type and whether the aggregate is exact.

Check your work Variance uses squared input units and needs enough nonnull rows.

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