SQL Server数学表达式 [英] SQL Server Mathhematical Expression

查看:198
本文介绍了SQL Server数学表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我会得到一个如下字符串,它将是一个数学表达式

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)(最大(最小(5,5),最大(5,9),最小(3,9))* 8 )+ 23 =?

i将在sql server中获取它,因为string.I需要通过sql server获取字符串的输出

。这个字符串纯动态。



如果有任何解决方案,请帮助我。



谢谢

Ayan

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

推荐答案

考虑到这一点,我认为这是一个糟糕的想法...



In SQL你可以执行动态查询,所以你可以做这样的事情

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
DECLARE @SQL VARCHAR(MAX) = 'SELECT (5+5)'
EXEC(@SQL)



您需要注意的一点是表达式的有效格式 - 在您的示例中并非所有表达式都是有效的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...


这篇关于SQL Server数学表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆