SUM in SQL Server

SUM is an aggregate function which is used to calculate the sum or total of values in a particular column.

Syntax:

SELECT SUM (<Column Name>) from <Table Name>

Example:

We have a table with the following data in the table SALES.

ITEMPRICE
ABC99.05
ABC1110.99
ABC270.89
ABC3100.99
ABC455.89


In order to count the total amount ( sum of the total prices) can be obtained by using SUM function.

QUERY:

SELECT SUM(PRICE) FROM SALES

Result Set:

Result set contains sum (total amount) of all the values in column PRICE.














Note:
  1. Sum function can be applied only on int , float , decimal , money data types.
  2. SUM Function ignores the NULL values in the columns.

This entry was posted in , . Bookmark the permalink.

Leave a reply