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

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

cdn.s3techtraining.com
from cdn.s3techtraining.com More from this publisher
17.06.2013 Views

Appendix A: System Functions CHECKSUM_AGG Like CHECKSUM, this is a basic hash algorithm usually used to detect changes or consistency in data. The primary difference is that CHECKSUM is oriented around rows, whereas CHECKSUM_AGG is oriented around columns. The basic syntax is: CHECKSUM_AGG( [ALL | DISTINCT] ) The expression value can be virtually anything, including, if you wish, concatenation of columns (just remember to cast as necessary); however, remember that expression order does matter, so if you’re concatenating, Col1 + Col2 does not equal Col2 + Col1. COUNT COUNT returns the number of items in expression. The data type returned is of type int. The syntax is as follows: COUNT ( [ALL | DISTINCT] | * ) The expression cannot be of the uniqueidentifier, text, image, or ntext data types. The * argument returns the number of rows in the table; it does not eliminate duplicate or NULL values. This function supports the OVER operator described in the ranking functions section of this appendix. COUNT_BIG COUNT_BIG returns the number of items in a group. This is very similar to the COUNT function just described, with the exception that the return value has a data type of bigint. The syntax is as follows: COUNT_BIG ( [ALL | DISTINCT ] | * ) Like COUNT, this function supports the OVER operator described in the ranking functions section of this appendix. GROUPING 592 GROUPING adds an extra column to the output of a SELECT statement. The GROUPING function is used in conjunction with CUBE or ROLLUP to distinguish between normal NULL values and those added as a result of CUBE and ROLLUP operations. Its syntax is: GROUPING ()

GROUPING is only used in the SELECT list. Its argument is a column that is used in the GROUP BY clause and that is to be checked for NULL values. This function supports the OVER operator described in the ranking functions section of this appendix. MAX The MAX function returns the maximum value from expression. The syntax is as follows: MAX([ALL | DISTINCT] ) MAX ignores any NULL values. This function supports the OVER operator described in the ranking functions section of this appendix. MIN The MIN function returns the smallest value from expression. The syntax is as follows: MIN([ALL | DISTINCT] ) MIN ignores NULL values. This function supports the OVER operator described in the ranking functions section of this appendix. STDEV The STDEV function returns the standard deviation of all values in expression. The syntax is as follows: STDEV() STDEV ignores NULL values. This function supports the OVER operator described in the ranking functions section of this appendix. STDEVP The STDEVP function returns the standard deviation for the population of all values in expression. The syntax is as follows: STDEVP() Apendix A: System Functions STDEVP ignores NULL values and supports the OVER operator described in the ranking functions section of this appendix. 593

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!