Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 execute formula stored as string

Author  Topic 

japss
Starting Member

1 Post

Posted - 2008-10-20 : 14:18:31
I have got a column in my table which stores mathematical formulas as strings. The base question is how do I evaluate the "string formula" to get result?

For example, I got a value like '2*5+2*5*4'.
I need a way to evaluate this string within an SQL Server stored procedure to get the result as 50

Declare @weight as string
Declare @output as numeric(18,2)

SET @weight = '2*5+2*5*4'.

Set @output = somefunction(@weight)

OutPut should be 50.

Thanks in advance for your help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-20 : 14:23:19
use sp_executesql and execute each of expressions usinf dynamic sql.

Declare @weight as string
Declare @output as numeric(18,2)

SET @weight = '2*5+2*5*4'.

sp_executesql @weight,@output OUT,..

look into books online to find syntax of sp_executesql
Go to Top of Page
   

- Advertisement -