Get SUM of VARCHAR values in SQL Server

PRA
 
on Sep 27, 2020 11:46 PM
660 Views

Hi!

I want get sum of to varchar number. 

declare @sum char(9) = '33,87', @sm char(9) = '55,83'
select REPLACE((Convert(MONEY, @sum) + Convert(MONEY, @sm )),',','.')

Result: 89.7

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Sep 27, 2020 11:53 PM

Hi PRA,

Refer below query.

SQL

DECLARE @sum CHAR(9) = '33,87', @sm CHAR(9) = '55,83'
SELECT CONVERT(MONEY,REPLACE(@sum,',','.')) + CONVERT(MONEY,REPLACE(@sm,',','.'))

Output

89.70