表A中 有 字段 service_no used
当service_no 从null 或者空字符串被更新为 其他字符串时
used 就被更新为Y
当service_no 从其他字符串被更新为 null或者空字符串时
used 就被更新为N
请指教谢谢
------解决方案--------------------
---try
create trigger auto_update on 表A
for update
as
if (select count(1) from deleted where service_no is null or service_no = ' ')> 0
update 表A set used = 'Y ' from inserted a where a.service_no = service_no
else
update 表A set used = 'N ' from inserted a where a.service_no = service_no
------解决方案--------------------
create table A(id int, service_no varchar(10), used char(1))
insert A select 1, 'AA ', NULL
insert A select 2, 'BB ', NULL
insert A select 3, ' ', NULL
create trigger tr on A
for update
as
if update(service_no)
update A set used=case when isnull(tmpA.service_no, ' ')= ' ' then 'N ' else 'Y ' end
from inserted tmpA
where tmpA.id=A.id