当前位置: 代码迷 >> Sql Server >> 新手有关问题,怎么让2个字段的值自动进行计算
  详细解决方案

新手有关问题,怎么让2个字段的值自动进行计算

热度:71   发布时间:2016-04-24 09:37:56.0
新手问题,如何让2个字段的值自动进行计算
SQL2000,字段A,B,C 怎么让字段A和B有值的时候自动计算C=A*B

请告诉下实现步骤,越详细越好,谢谢。
------解决思路----------------------
触发器可以实现,试试下面的代码:

create trigger tri_cal on tb for insert,update
as
       if exists(select a,b from tb where a is not null and b is not null)
          update tb set c=a+b

------解决思路----------------------
select A,B,(case when isnull(A,'')='' or isnull(B,'')=''	then '' 
else A*B end) as C
from Tb

------解决思路----------------------
引用
create trigger tri_cal on tb for insert,update
as
       if exists(select a,b from tb where a is not null and b is not null)
          update tb set c=a+b

并发太多,竟然出现了网络异常嘛,小调一下:

create trigger tri_cal on tb for insert,update
as
       if exists(select a,b from tb where a is not null and b is not null)
          update tb set c=a*b

--当
insert into tb(a,b) values(1,2)

update tb set a=3,b=4 时,即触发触发器,可实现自动计算


  相关解决方案