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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with rounding to 2 decimal places

Author  Topic 

jodders
Starting Member

41 Posts

Posted - 2012-01-13 : 11:55:52

Hi guys,

I am writing a script and stuck on a round element which I am struggling at fixing. My code at the moment outputs the result to 6 decimal places instead of 2 decimal places.


sum(case when acct_type <> 'I' then sign*(amount*rate) else 0 end)


Result: 0.005270

I had ago at modifying my code but having no such luck. any pointers?



convert(money,(sum(round(case when acct_type <> 'I' then sign*(amount*rate) else 0 end)))))

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-13 : 12:10:59
just make it like

cast(sum(case when acct_type <> 'I' then sign*(amount*rate) else 0 end) as decimal(20,2))

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jodders
Starting Member

41 Posts

Posted - 2012-01-13 : 12:12:13
visakh16, thanks very much. You are very kind
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-13 : 12:20:25
np
you're welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -