for update 触发器的写法:关于更新前和更新后的字段比较
表A中的有一个字符串字段result,例如:0000。
在写for update触发器时,如何比较更新前和更新后的该字段中的某一位。
CREATE trigger insert_task on A
for update
as
if update(result)
begin
declare @rst nvarchar(1)
select @rst=left(result, 1) from inserted
if(@rst='1')
begin
insert into B from inserted
end
end
我写的这个触发器毛病在于,left(result,1)这一位如果更新前和更新后,没有变化,而其他位数变化了,也会往B表插入数据,我的要求是只判断left(result,1)这一位是否变化了,才做操作。