当前位置: 代码迷 >> Sql Server >> 哪位高手帮小弟我看看小弟我写的触发器,小弟我不知道是哪错了,能创建,但是不执行~
  详细解决方案

哪位高手帮小弟我看看小弟我写的触发器,小弟我不知道是哪错了,能创建,但是不执行~

热度:76   发布时间:2016-04-27 18:50:03.0
谁帮我看看我写的触发器,我不知道是哪错了,能创建,但是不执行~~
谁帮我看看我写的触发器,我不知道是哪错了,能创建,但是不执行~~

insert   into   Integral   values(3,50)
drop   trigger   UpdateGroup
create   trigger   UpdateGroup   on   integral
    for   update
    as
    declare   @in_integral     int /*积分*/
    declare   @us_id bigint /*用户ID*/
    set   @in_integral   =   (select   in_integral   from   integral   where   us_id   =   @us_id)
    set   @us_id   =   (select   us_id   from   inserted)

    begin
if(@in_integral   > =   100)   and   (@in_integral   <   500)
begin
update   Group_User   set   gr_id   =   3   where   us_id   =   @us_id
end
if(@in_integral   > =   500)   and   (@in_integral   <   1000)
begin
update   Group_User   set   gr_id   =   4   where   us_id   =   @us_id
end
if(@in_integral   > =   1000)   and   (@in_integral   <   2000)
begin
update   Group_User   set   gr_id   =   5   where   us_id   =   @us_id
end
if(@in_integral   > =   2000)   and   (@in_integral   <   3500)
begin
update   Group_User   set   gr_id   =   6   where   us_id   =   @us_id  
end
if(@in_integral   > =   3500)   and   (@in_integral   <   5000)
begin
update   Group_User   set   gr_id   =   7   where   us_id   =   @us_id  
end
if(@in_integral   > =   5000)   and   (@in_integral   <   8000)
begin
update   Group_User   set   gr_id   =   8   where   us_id   =   @us_id
end
if(@in_integral   > =   8000)
begin
update   Group_User   set   gr_id   =   9   where   us_id   =   @us_id
end  
    end

------解决方案--------------------
[email protected]_id吧?

set @us_id = (select us_id from inserted)
set @in_integral = (select in_integral from integral where us_id = @us_id)[email protected]_id=NULL
  相关解决方案