Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,

i am getting
C#
Arithmetic overflow error converting varchar to data type numeric.
this error.
the code script is below
C#
Declare @Amount Decimal(18,4)

Declare @strSql VARCHAR(MAX)

SET @strSql =''

SET @strSql = 'UPDATE TABLE1 SET col1='+@Amount+' where id=1'
print @strSql 

--EXEC(@strSql)


i am using exec because the where condition is dynamic.the table column is also has the same type.

Please help me out.

Thanks
Posted
Comments
phil.o 24-Feb-14 11:47am    
What is the current value of @Amount when your procedure throws its error?
S.P.Tiwari 24-Feb-14 12:13pm    
well i was passing 0.25 .

Two things you need to fix:
1) Give @Amount a value - at present it is null, so it won;t work too well.
2) Convert @Amount to a VARCHAR

SQL
Declare @Amount Decimal(18,4)
Declare @strSql VARCHAR(MAX)
SET @strSql =''
SET @Amount=0.0
SET @strSql = 'UPDATE TABLE1 SET col1='+CONVERT(VARCHAR, @Amount)+' where id=1'
print @strSql
 
Share this answer
 
Comments
S.P.Tiwari 24-Feb-14 12:11pm    
thanks griff. i will check this. well i was passing 0.25 .
S.P.Tiwari 25-Feb-14 2:33am    
Thanks Griff. its working fine. thanks again
OriginalGriff 25-Feb-14 3:09am    
You're welcome!
 
Share this answer
 
Comments
S.P.Tiwari 25-Feb-14 2:33am    
THANKS TADIT. ITS working fine
Most welcome buddy. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900