Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to round off in sql server

Posted on 2013-12-28
3
Medium Priority
?
319 Views
Last Modified: 2014-01-20
SELECT round(AVG(CONVERT(dECIMAL(10,2),IMS)),2) fROM IND13I.DBO.MSTMASSSTUDENTS
WHERE Course='B.Arch' and semester=1 and subjectcode='ar-101'
and ims not in('i','e','l','','ab')

The result is 30.800000

Why not 30.80
0
Comment
Question by:searchsanjaysharma
3 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39743748
Not sure why, but ROUND does the rounding, but does not alter the percision/scale of the value being rounded.  

CAST(your_number as decimal(19,2)) will return only two decimal places.
SELECT ROUND(18.2000000,2)
SELECT CAST(18.200000 as decimal(19,2))

Open in new window

0
 
LVL 12

Accepted Solution

by:
Gregory Miller earned 2000 total points
ID: 39743758
SELECT CAST(round(AVG(CONVERT(dECIMAL(10,2),IMS)),2) AS DECIMAL, 2)

Open in new window

0
 

Author Closing Comment

by:searchsanjaysharma
ID: 39793814
tx
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question