SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Decimal places
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mosiki
Starting Member

12 Posts

Posted - 06/24/2013 :  11:49:40  Show Profile  Reply with Quote

Hi

How can I get the below query to return the result to 2 decimal places?

(SUM(Soccer_Base.dbo.Results.AwayFT) + SUM(Soccer_Base.dbo.Results.HomeFT))
			  / COUNT(Soccer_Base.dbo.Results.AwayTeam) AS GPG


Thanks

Mosiki

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 06/24/2013 :  11:53:41  Show Profile  Reply with Quote

convert(
numeric(19,2),
(SUM(Soccer_Base.dbo.Results.AwayFT) + SUM(Soccer_Base.dbo.Results.HomeFT))
			  / COUNT(Soccer_Base.dbo.Results.AwayTeam)
)

Cheers
MIK

Edited by - MIK_2008 on 06/24/2013 11:54:18
Go to Top of Page

mmkrishna1919
Yak Posting Veteran

India
94 Posts

Posted - 06/25/2013 :  00:56:32  Show Profile  Reply with Quote
You can also use ROUND function..

ROUND(
(SUM(Soccer_Base.dbo.Results.AwayFT) +
SUM(Soccer_Base.dbo.Results.HomeFT))
/ COUNT(Soccer_Base.dbo.Results.AwayTeam)
,2)
AS GPG

Thanks..


M.MURALI kRISHNA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 06/25/2013 :  01:03:58  Show Profile  Reply with Quote
quote:
Originally posted by mmkrishna1919

You can also use ROUND function..

ROUND(
(SUM(Soccer_Base.dbo.Results.AwayFT) +
SUM(Soccer_Base.dbo.Results.HomeFT))
/ COUNT(Soccer_Base.dbo.Results.AwayTeam)
,2)
AS GPG

Thanks..


M.MURALI kRISHNA


you'll get the value rounded to 2 decimal places but result may still contain additional 0s after decimal based on highest scale value among the involved columns

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000