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 05, 2012 5:31 AM
 Valued Member Group: General Forum Members Last Login: Tuesday, November 12, 2013 5:46 AM Points: 68, Visits: 138
 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 05, 2012 5:32 AM
 SSCertifiable Group: General Forum Members Last Login: Wednesday, August 28, 2013 2:37 AM Points: 5,075, Visits: 4,834
 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 05, 2012 5:36 AM
 SSC Journeyman Group: General Forum Members Last Login: Tuesday, November 12, 2013 4:06 AM Points: 81, Visits: 289
 is your chargeAmount is INT then you need to convert it to decimal to get decimal in SUM
Post #1381023
 Posted Monday, November 05, 2012 5:51 AM
 Valued Member Group: General Forum Members Last Login: Tuesday, November 12, 2013 5:46 AM Points: 68, Visits: 138
 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 05, 2012 5:53 AM
 SSCertifiable Group: General Forum Members Last Login: Wednesday, August 28, 2013 2:37 AM Points: 5,075, Visits: 4,834
Post #1381032
 Posted Monday, November 05, 2012 6:09 PM
 Old Hand Group: General Forum Members Last Login: Saturday, November 16, 2013 3:05 PM Points: 369, Visits: 1,192
 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