## How to convert to two decimal places

 Author Message hoseam SSCrazy Group: General Forum Members Points: 2302 Visits: 467 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? anthony.green SSC-Forever Group: General Forum Members Points: 47217 Visits: 7624 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. How to post data/code for the best help - Jeff ModenNeed a string splitter, try this - Jeff ModenHow to post performance problems - Gail ShawManaging Transaction Logs - Gail ShawTroubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger BriPan SSC Eights! Group: General Forum Members Points: 859 Visits: 296 is your chargeAmount is INT then you need to convert it to decimal to get decimal in SUM hoseam SSCrazy Group: General Forum Members Points: 2302 Visits: 467 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. anthony.green SSC-Forever Group: General Forum Members Points: 47217 Visits: 7624 Vedran Kesegic Hall of Fame Group: General Forum Members Points: 3840 Visits: 1266 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