Foxtable(狐表)用户栏目专家坐堂 → 求教有关SQL触发器编写


  共有14062人关注过本帖树形打印复制链接

主题:求教有关SQL触发器编写

帅哥哟,离线,有人找我吗?
baoxyang
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐精 帖子:3313 积分:23146 威望:0 精华:1 注册:2009/3/31 11:25:00
求教有关SQL触发器编写  发帖心情 Post By:2011/12/28 20:35:00 [显示全部帖子]

CREATE TRIGGER 个税计算 ON dbo.工资明细
FOR  UPDATE,INSERT
AS
declare @K double
    if Update(应发工资) or Update( 扣除社保)
       begin
             set  @K= (b.应发工资 - b.扣除社保) - 3500
             if @K >= 4000 and @K < 5000 then

             end
             if @K >= 5000 and @K < 6000 then
                    @j = 45
             if @K >= 6000 and @K < 8000 then
                    @j = 145
             if @K >= 8000 and @K < 9000 then
                    @j = 345
             if @K >= 9000 and @K < 10000 then
                    @j = 545
             if @K >= 10000 and @K < 15000 then
                    @j = 745
             if @K >= 15000 and @K < 19000 then
                    @j = 1870
             if @K >= 19000 and @K < 20000 then
                    @j = 2870
             if @K >= 20000 and @K < 38600 then
                    @j = 3120
             if @K >= 38600 and @K < 50000 then
                    @j = 7775
             if @K >= 50000 and @K < 70000 then
                    @j = 11195
             if @K >= 70000 then
                    @j = 17770
            Update 工资明细
            set 扣除所得税 = @j
            from 工资明细 a,Inserted b
            where a.ID = b.ID15
               
      end

实现目的是想SQL服务器,当修改表列应发工资或扣除社保字段数据时,触发产生自动计算所得税。请教以上如何修改才能实现?先谢了!!

 


 回到顶部