Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Aggregate FunctionsRSS Feeds

CHECKSUM_AGG Function

Posted By: Sarita Patel     Category: SQL Server     Views: 4912

This article explains CHECKSUM_AGG function of sql server with different examples.

CHECKSUM_AGG function is used to get checksum of values in a group. It ignores null values in computation.

CHECKSUM_AGG can be used along with BINARY_CHECKSUM to detect changes in a table.

The order of the rows in the table does not affect the result of CHECKSUM_AGG. In addition, CHECKSUM_AGG functions may be used with the DISTINCT keyword and the GROUP BY clause.

 

Syntax of CHECKSUM function :

CHECKSUM ( * | expression [ ,...n ] )

means that the computation is over all the columns of the table.

Expression is any valid sql expression of any type.

 



Example of CHECKSUM function :

Example 1 : Use of CHECKSUM_AGG function in SELECT clause to get checksum in group

SELECT   CHECKSUM_AGG(CONVERT(INT,UnitsInStock))

FROM   Products

 

Output

 50

 

Now update some of the rows and again run the query.

 

UPDATE Products

SET         UnitsInStock = 15

WHERE  UnitsInStock < 10

  

SELECT  CHECKSUM_AGG(CONVERT(INT,UnitsInStock))

FROM     Products


Output

61

 

Above example displays checksum of unit price field in the products table.

 


Example 2 : Using CHECKSUM_AGG function with BINARY_CHECKSUM to detect changes in a table

SELECT  CHECKSUM_AGG(BINARY_CHECKSUM(UnitsInStock))

FROM     Products

 

Output

7913472


Above example displays checksum to detect changes in the unit in stock field of product table.

  
Share: 

 
 
 

Didn't find what you were looking for? Find more on CHECKSUM_AGG Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of CHECKSUM_AGG Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!