Saturday, December 13, 2008

ROUND() function in sql

Syntax:
ROUND ( numeric_expression , length [ ,function ] )

numeric_expression Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
length Is the precision to which numeric_expression is to be rounded. length must be an expression of type tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.
function Is the type of operation to perform. function must be tinyint, smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.

SELECT ROUND(column_name,decimals) FROM table_name

Parameter Description column_name Required. The field to round. decimals Required. Specifies the number of decimals to be returned.
1. SELECT ROUND(10.09 ,1) = 10.1
2. SELECT ROUND(10.09 ,-1) = 10

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory