November 5, 2012 at 5:31 am
Hi
I have this code here
case
when chargeType <> 'ADV_SWITCH_FEE'
then CAST(isNull(sum(chargeAmount)/100.0, 0.0) AS VARCHAR)
else ''
end as chargeAmount
How do I convert my "sum" into decimal places?
November 5, 2012 at 5:32 am
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.
November 5, 2012 at 5:36 am
is your chargeAmount is INT then you need to convert it to decimal to get decimal in SUM
November 5, 2012 at 5:52 am
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.
November 5, 2012 at 5:53 am
cast the inner sum as decimal then case the whole output as varchar
November 5, 2012 at 6:09 pm
Use STR function. E.g:
declare @x money=12345.69851
SELECT [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)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply