Aggregate Functions and Datatypes

SUM and AVG can be used only with numeric columns ¾ int, smallint, tinyint, decimal, numeric, float, real, money, and smallmoney datatypes. MIN and MAX cannot be used with bit datatypes. Aggregate functions other than COUNT(*) cannot be used with text and image datatypes.

With these exceptions, the other aggregate functions can be used with any type of column. For example, in a character datatype column, you can use MIN (minimum) to find the lowest value, the one closest to the beginning of the alphabet, as shown in the following example:

SELECT MIN(au_lname)
FROM authors

--------------------
Bennet

(1 row(s) affected)

When you sum or average integer data, Transact-SQL treats the result as an int value, even if the datatype of the column is smallint or tinyint.