Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi ,
I will get a string like below , it will be a mathematical expression
1)5+5*+Min(5,5,9)=?
2)Max(5+5,5+9,8-3)+6=?
3)Max((5+5),(5+9),(8-3))*9=?
4)(Max(Min(5,5),Max(5,9),Min(3,9))*8)+23=?
i will get it in sql server , as string.I need to get the output
of the string by sql server.This string purely dynamic.

Please help me , if any solution is available.

Thanks
Ayan
Posted
Comments
ZurdoDev 9-Nov-15 7:46am    
Do you know how to execute dynamic sql? You can use EXEC (@sql) where @sql is a variable that has valid sql in it.

1 solution

With the consideration, that this looks me as an awful idea...

In SQL you can execute dynamic queries, so you can do something like this
SQL
DECLARE @SQL VARCHAR(MAX) = 'SELECT (5+5)'
EXEC(@SQL)

One point you have to take care of is the valid format of the expressions - in your samples not all expressions are valid SQL...
 
Share this answer
 
Comments
dear.banerjee 12-Nov-15 7:33am    
Then how will execute Max(5+5,5+9,8-3) ?
Please be sure before answering a question , i have 10 years of experience
Kornfeld Eliyahu Peter 12-Nov-15 14:19pm    
If you had a single week of experience, you would know that MAX in SQL is NOT a mathematical function like in C and like...
As I stated above - your statement must be a valid SQL statement to execute it in such way...

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