日期:2014-05-19  浏览次数:20726 次

请问一个触发器的问题
我写了一个触发器如下,是当resume表的jlzt   like   1111%时,更新其它字段一下,
其它情况更新情况不同,但是检查语法没错误,但是运行时却有问题,帮我看看.

CREATE   TRIGGER   [upjlzttojl]   ON   [dbo].[Resume]  
FOR     UPDATE  
AS
begin
      if   update(jlzt)
      begin
            declare   @jlzt   varchar(15)
            select   @jlzt=jlzt   from   updated
            if   @jlzt   like   '1111111111% '
update   resume   set   zjl=3   from   updated   where   reid=updated.reid
            else   if   @jlzt   like   '1111% '
update   resume   set   zjl=2   from   updated   where   reid=updated.reid
            else   if   @jlzt   like   '0000000000% '
update   resume   set   zjl=0   from   updated   where   reid=updated.reid
            else
update   resume   set   zjl=1   from   updated   where   reid=updated.reid
      end
      if   update(ejlzt)
      begin
            declare   @ejlzt   varchar(15)
            select   @ejlzt=ejlzt   from   updated
            if   @ejlzt   like   '1111111111% '
update   resume   set   ejl=3   from   updated   where   reid=updated.reid
            else   if   @ejlzt   like   '1111% '
update   resume   set   ejl=2   from   updated   where   reid=updated.reid
            else   if   @ejlzt   like   '0000000000% '
update   resume   set   ejl=0   from   updated   where   reid=updated.reid
            else
update   resume   set   ejl=1   from   updated   where   reid=updated.reid
      end
end

------解决方案--------------------
begin
declare @jlzt varchar(15)
set @jlzt=jlzt
select @jlzt from updated
if @jlzt like '1111111111% '
------解决方案--------------------
CREATE TRIGGER [upjlzttojl] ON [dbo].[Resume]
FOR UPDATE
AS
begin
if update(jlzt)

begin
declare @jlzt varchar(15)

if (select count(1) from updated where jlzt like '1111111111% ') > 0
update resume set zjl=3 from updated where reid=updated.reid
else if (select count(1) from updated where jlzt like '1111% ') > 0
update resume set zjl=2 from updated where reid=updated.reid
else if (select count(1) from updated where jlzt like '0000000000% ') > 0
update resume set zjl=0 from updated where reid=updated.reid
else
update resume set zjl=1 from updated where reid=updated.reid
end
if update(ejlzt)
begin
declare @ejlzt varchar(15)
select @ejlzt=ejlzt from updated where ejlzt like '1111111111% ' <