VAR returns the statistical variance of the given values.
VAR ignores NULL values.
Use VAR if the values represent a sample.
Use VARP if the values represent the entire population.
This example returns the variance of all sales.
SELECT VAR(TotalAmount) AS 'Variance'
FROM [Order]
| Variance |
|---|
| 3962543.95098209 |
Syntax of the VAR function.
VAR(value)
value -- a number or numeric column.
| PRODUCT |
|---|
| Id |
| ProductName |
| SupplierId |
| UnitPrice |
| Package |
| IsDiscontinued |
| SUPPLIER |
|---|
| Id |
| CompanyName |
| ContactName |
| City |
| Country |
| Phone |
| Fax |
SELECT S.CompanyName,
VAR(UnitPrice) AS 'Price Variance'
FROM Product P
JOIN Supplier S ON S.Id = P.SupplierId
GROUP BY S.CompanyName
| CompanyName | Price Standard Deviation |
|---|---|
| Aux joyeux ecclésiastiques | 30135.125 |
| Bigfoot Breweries | 5.33333333333331 |
| Cooperativa de Quesos 'Las Cabras' | 144.5 |
| Escargots Nouveaux | NULL |
| Exotic Liquids | 24.3333333333333 |
![]() |
|
Note: A NULL value is returned when a supplier has less than 2 products.