The SQL ROUND function is used to round a numeric field in a table to the number of decimals specified.
Employees Table
employeeID | employeeName | yearsOfService |
1000 | John Smith | 10.25 |
1001 | Fred White | 22.53 |
1002 | Jane Scott | 17.4 |
1003 | Samuel Williams | 9.9 |
In this example, we want to round the results of the yearsOfService to the
nearest whole number.
Syntax
SELECT ROUND(column_name, decimals)
FROM Table |
Example
SELECT employeeName as [Employee Name], ROUND(yearsofService,0) as [Years of Service]
FROM employees
|
Results
Employee Name | Years of Service |
John Smith | 10 |
Fred White | 23 |
Jane Scott | 17 |
Samuel Williams | 10 |
The SQL ROUND function is very useful when you need to round the numbers in the result set to a specific number of decimal places.
Did you find the page informational and useful? Share it using one of your favorite social sites.
Recommended Books & Training Resources