Wednesday, April 12, 2017

SUM() in SQL Server


SQL SUM() function is used to return the total sum value of a column. The SUM() can only be applied on numeric type column. The SUM() determines the total of all the non-NULL values in the columns, NULL values are ignored.

Syntax:

     
            SELECT SUM(ALL | DISTINCT column_name) FROM table_name


column_name is the name of the column of which total is to be calculated.

table_name is the name of the table


Example 1:
SUM() on column which does not have any NULL value.

SELECT * FROM TempEmployeePayHistory



SELECT SUM(Rate) FROM TempEmployeePayHistory



Example 2:
SUM() on column having NULL values.

          SELECT * FROM TempEmployeePayHistory



SELECT SUM(Rate) FROM TempEmployeePayHistory



Example 3:

SUM() on non-numeric column.



Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: