Convert varchar into int
Posted on 2013-06-11
Trying to convert data in varchar format into an integer so I can sum the values.
However, some of the data contains strings like '-11.73' or '$1.23' or '$1,500'
I am getting the error below with this code. Please help. Thanks.
Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the varchar value '-11,73' to data type int.
'YTD' as "Totals"
,'System' as "Type"
,count(distinct c.ch_trade_error_id) as "Total Trade Errors"
,sum(case when cast(replace(c.amount,'.',',') as int) *-1 < 0 then cast(replace(c.amount,'.',',') as int) else 0 end) as Gain
c.ORIGINATION_DATE between '2013-01-01' and '2013-05-31'
and c.REP_NAME is null