Monday, April 17, 2017

ROUND() in SQL Server


SQL ROUND() function is used to return the numeric value rounded to certain decimal or precision. NULL values are not rounded off. ROUND() does not work on non-numeric columns such as text.


Syntax:

     
            SELECT ROUND (numeric_expression, length)


numeric_expression is the numeric value to be rounded off.

length is the number of decimal places up to which numeric value should be rounded off.


Example 1:
ROUND() on numeric column.

SELECT * FROM TempEmployeePayHistory



SELECT Rate, ROUND(Rate, 2) FROM TempEmployeePayHistory



Example 2:
ROUND() on column with NULL values.

          SELECT * FROM TempEmployeePayHistory



SELECT Rate, ROUND(Rate, 2) FROM TempEmployeePayHistory



Example 3:
ROUND() on text column.

          SELECT * FROM DatabaseLog



          SELECT [Event], ROUND([Event], 2) FROM DatabaseLog



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: