谁帮我看看我写的触发器,我不知道是哪错了,能创建,但是不执行~~
谁帮我看看我写的触发器,我不知道是哪错了,能创建,但是不执行~~
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
------解决方案----------------------应该先获得@us_id吧?
set @us_id = (select us_id from inserted)
set @in_integral = (select in_integral from integral where us_id = @us_id)--@us_id=NULL