Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

I have following query:

ChargeFormula varchar(8000) null
Charge numeric(18, 0) null

I have following value in the table ChargeMaster

ChargeID : 1003
ChargeDesc : SinkingFund
ChargeFormula : (400.00*0.75)/100)/12
Charge : NULL
ChargeStatus : Y

Now I want to use the formula which is in the ChargeFormula field and put the value calculated in the Charge column. But the ChargeFormula column is nvarchar and Charge is numeric. I am facing problem to convert the value.

Please Help.

Thanks in Advance..

Vinay D Sarmalkar
Updated 15-Mar-11 4:24am

This[^] thread has a Stored Procedure definition that does what the two previous replies do. Which you may find useful.
Share this answer
Espen Harlinn 15-Mar-11 17:49pm    
Right, my 5 - you obviously meant sp_executesql :)
Try this

declare @tmp varchar(100)
select @tmp=formula from table
exec sqltextquery @tmp
Share this answer
Something like below will convert to int but as you have Charge numeric(18, 0) null output returns 0(as you have 0 decimal places to return) where actual output is 0.25000
select cast((select (((400.00*0.75)/100)/12) as test) as int)
Share this answer

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