The COMPUTE Clause

In Chapter 4, you learned how to use aggregate functions to produce summary data. Queries using aggregate functions show only summary information by grouping data.

The Transact-SQL COMPUTE clause provides the capability to create reports that show detailed and summary information.

Caution

COMPUTE is not an ANSI standard feature.

To add summary information to any standard query, just add the COMPUTE clause at the end of the query, specifying which aggregate function to compute, as in Listing 11.18.

Code Listing 11.18. Use COMPUTE to Show Summary Information at the End of a Standard Query
					 -- This is a normal query to retrieve ...

Get Microsoft® SQL Server™ 2000 Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.