Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 How to convert to two decimal places Rate Topic Display Mode Topic Options
Author
 Message
 Posted Monday, November 5, 2012 5:31 AM
 SSC Veteran Group: General Forum Members Last Login: Sunday, November 13, 2016 11:04 PM Points: 233, Visits: 427
 HiI have this code herecase when chargeType <> 'ADV_SWITCH_FEE' then CAST(isNull(sum(chargeAmount)/100.0, 0.0) AS VARCHAR) else '' end as chargeAmountHow do I convert my "sum" into decimal places?
Post #1381020
 Posted Monday, November 5, 2012 5:32 AM
 SSCertifiable Group: General Forum Members Last Login: Thursday, September 1, 2016 2:56 AM Points: 5,969, Visits: 6,067
 You will need to convert it to a data type which allows you to specify the amount of decimal places you want, you would want decimal with the correct precision to cope with how ever many decimal places you need.
Post #1381021
 Posted Monday, November 5, 2012 5:36 AM
 SSC Journeyman Group: General Forum Members Last Login: Friday, January 31, 2014 4:06 AM Points: 83, Visits: 296
 is your chargeAmount is INT then you need to convert it to decimal to get decimal in SUM
Post #1381023
 Posted Monday, November 5, 2012 5:51 AM
 SSC Veteran Group: General Forum Members Last Login: Sunday, November 13, 2016 11:04 PM Points: 233, Visits: 427
 My charge amount need to cater for both "Then" and "Else", my "else" returns string hence I cast it as varchar. that code so far is working but I need to return two decimal value amount.
Post #1381031
 Posted Monday, November 5, 2012 5:53 AM
 SSCertifiable Group: General Forum Members Last Login: Thursday, September 1, 2016 2:56 AM Points: 5,969, Visits: 6,067
Post #1381032
 Posted Monday, November 5, 2012 6:09 PM
 Old Hand Group: General Forum Members Last Login: Monday, November 14, 2016 4:53 AM Points: 370, Visits: 1,252
 Use STR function. E.g:`declare @x money=12345.69851SELECT [STR]=STR(@x, 20, 2), [CONVERT_default]=CONVERT(varchar(20), @x), [CONVERT_format_1]=CONVERT(varchar(20), @x, 1), [CONVERT_format_2]=CONVERT(varchar(20), @x, 2)` _____________________________________________________Microsoft Certified Master: SQL Server 2008XDetails Addin - for SQL Developersblog.sqlxdetails.com - Transaction log myths
Post #1381332

 Permissions