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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appendix A: System Functions<br />

CHECKSUM_AGG<br />

Like CHECKSUM, this is a basic hash algorithm usually used to detect changes or consistency in data. The<br />

primary difference is that CHECKSUM is oriented around rows, whereas CHECKSUM_AGG is oriented<br />

around columns. The basic syntax is:<br />

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

The expression value can be virtually anything, including, if you wish, concatenation of columns (just<br />

remember to cast as necessary); however, remember that expression order does matter, so if you’re concatenating,<br />

Col1 + Col2 does not equal Col2 + Col1.<br />

COUNT<br />

COUNT returns the number of items in expression. The data type returned is of type int. The syntax is<br />

as follows:<br />

COUNT<br />

(<br />

[ALL | DISTINCT] | *<br />

)<br />

The expression cannot be of the uniqueidentifier, text, image, or ntext data types. The * argument<br />

returns the number of rows in the table; it does not eliminate duplicate or NULL values.<br />

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

COUNT_BIG<br />

COUNT_BIG returns the number of items in a group. This is very similar to the COUNT function just<br />

described, with the exception that the return value has a data type of bigint. The syntax is as follows:<br />

COUNT_BIG<br />

(<br />

[ALL | DISTINCT ] | *<br />

)<br />

Like COUNT, this function supports the OVER operator described in the ranking functions section of this<br />

appendix.<br />

GROUPING<br />

592<br />

GROUPING adds an extra column to the output of a SELECT statement. The GROUPING function is used<br />

in conjunction with CUBE or ROLLUP to distinguish between normal NULL values and those added as a<br />

result of CUBE and ROLLUP operations. Its syntax is:<br />

GROUPING ()

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

Saved successfully!

Ooh no, something went wrong!