表达式的SQL语句如何书写

表tb有字段a,b,c,d

a :float;
b:float;
c:float;
d:varchar;

现字段d的值是这样的
b+c或是b-c或是b*c这类的一个表达式,

那么Sql语句如何写符合

update tb set a=d(这句是错的)

意思是字段a的值是由字段d的表达式所计算出的结果。
示例如下:
b c d a
1 3 b+c 》 4
1 3 b*c 》 3
1 3 b-c 》 -2
由字段b,c ,d推出a的值。谢谢。明天过来看答案。

---------------------------------------------------------------

就象你上面这样写,写 b+c 这样的就行了。运行时就要用动态SQL执行了。
declare @sql varchar(8000)
select @sql=''
selelct @sql='update mytable set a='+d+' where d='''+d+'''
from mytable

exec (@sql)

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus