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
--当
insert into tb(a,b) values(1,2)
或
update tb set a=3,b=4 时,即触发触发器,可实现自动计算