17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

❑ CHECKSUM_AGG<br />

❑ COUNT<br />

❑ COUNT_BIG<br />

❑ GROUPING<br />

❑ MAX<br />

❑ MIN<br />

❑ STDEV<br />

❑ STDEVP<br />

❑ SUM<br />

❑ VAR<br />

❑ VARP<br />

In most aggregate functions, the ALL or DISTINCT keywords can be used. The ALL argument is the<br />

default and will apply the function to all the values in the expression, even if a value appears numerous<br />

times. The DISTINCT argument means that a value will only be included in the function once, even<br />

if it occurs several times.<br />

Aggregate functions cannot be nested. The expression cannot be a subquery.<br />

AVG<br />

AVG returns the average of the values in expression. The syntax is as follows:<br />

AVG([ALL | DISTINCT] )<br />

The expression must contain numeric values. NULL values are ignored. This function supports the<br />

OVER operator described in the ranking functions section of this appendix.<br />

CHECKSUM<br />

This is a basic hash algorithm usually used to detect changes or consistency in data. This particular function<br />

accepts either an expression as an argument or a * (which implies that you want all columns in all<br />

the joined tables to be included). The basic syntax is:<br />

CHECKSUM(, […n] | * )<br />

Note that the order of your expression — or in the case of a *, the join order — will affect the checksum<br />

value, so, for example:<br />

CHECKSUM(SalesOrderID, OrderDate)<br />

would not give the same result as:<br />

CHECKSUM(OrderDate, SalesOrderID )<br />

This function is NOT compatible with the OVER operator.<br />

Apendix A: System Functions<br />

591

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!