How Can I Execute a Formula stored as a string

KevinM

Registered User.
Local time
Today, 12:03
Joined
Jun 15, 2000
Messages
719
In my SQL Server table I have a field that stores a literal string math formula, i.e '2*3', '2(3+5)', '2*3' etc

How can I execute this actual formula and produce a result via a view, UDF or stored procedure?

I'm looking for the MS Access equivalent of the 'EVAL' function which for security reasons isn't available in T-SQL.

Many Thanks.
 
Thanks Wayne

In the example in the link how do I replace the variable @Value = '1+0.25' with a column name 'MyColumn' from a VIEW 'MyView'?
 
Kevin,

How about something like:

Select @Value = MyColumn From MyView Where ..."

Wayne
 
Thanks

I've tried that but it only returns one null column, I need it to execute on every row in myVIew which I can't seem to get it to do.

Here is my code....

DECLARE @Value Varchar(200),
@Sel NVARCHAR(2000),
@Result decimal(3,2)

SELECT @Value= MyColumn FROM myView
SET @Sel = N'SELECT @Result = ' + @Value
EXEC sp_executesql @Sel, N'@Result decimal(3,2) OUTPUT',
@Result = @Result OUTPUT
SELECT @Result

Thanks again
 

Users who are viewing this thread

Back
Top Bottom