Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Decimal places

Author  Topic 

mosiki
Starting Member

12 Posts

Posted - 2013-06-24 : 11:49:40

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
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-06-24 : 11:53:41
[code]
convert(
numeric(19,2),
(SUM(Soccer_Base.dbo.Results.AwayFT) + SUM(Soccer_Base.dbo.Results.HomeFT))
/ COUNT(Soccer_Base.dbo.Results.AwayTeam)
)
[/code]
Cheers
MIK
Go to Top of Page

mmkrishna1919
Yak Posting Veteran

95 Posts

Posted - 2013-06-25 : 00:56:32
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

52326 Posts

Posted - 2013-06-25 : 01:03:58
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
   

- Advertisement -