ROUND Function in SQL Server - sql - sql tutorial - learn sql



  • The ROUND function in SQL is used to round a number to a specified precision.
  • The ROUND function returns a number rounded to a certain number of decimal places.
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Syntax:

  • The syntax for the ROUND function is,
ROUND (expression, [decimal place])
  • where [decimal place] indicates the number of decimal points returned. A negative number means the rounding will occur to a digit to the left of the decimal point.
  • For example, -1 means the number will be rounded to the nearest tens.
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Examples:

  • We use the following table for our examples.

Table Wikitechy_Student_Rating

Column Name Data Type
StudentID integer
First_Name char(20)
Rating float
  • and this table contains the following rows:

Table Wikitechy_Student_Rating

StudentID First_Name Rating
1 Jenny 85.235
2 Bob 92.52
3 Alice 3.9
4 James 120.1

Example 1: Decimal place is positive

  • To round to the nearest tenths place, we use the following SQL:
SELECT First_Name, ROUND (Rating, 1) Rounded_Score FROM Wikitechy_Student_Rating;

Result:

First_Name Rounded_Score
Jenny 85.2
Bob 92.5
Alice 3.9
James 120.1

Example 2: Decimal place is negative

  • To round to the nearest tens place, we use the following SQL:
SELECT First_Name, ROUND (Rating, -1) Rounded_Score FROM Wikitechy_Student_Rating;

Result:

First_Name Rounded_Score
Jenny 90
Bob 90
Alice 0
James 120

This tutorial provides more the basic needs and informations on sql tutorial , pl sql tutorial , mysql tutorial , sql server , sqlcode , sql queries , sql , sql formatter , sql join , w3schools sql , oracle tutorial , mysql , pl sql , learn sql , sql tutorial for beginners , sql server tutorial , sql query tutorial , oracle sql tutorial , t sql tutorial , ms sql tutorial , database tutorial , sql tutorial point , oracle pl sql tutorial , oracle database tutorial , oracle tutorial for beginners , ms sql server tutorial , sql tutorial pdf

Related Searches to ROUND Function in SQL Server