将sybase触发器转换为mssql触发器

时间:2014-10-16 06:34:50

标签: sql sql-server sybase

我的任务是将ASA迁移到MSSQL数据库但是我不熟悉MSSQL触发器,有人可以将其转换为MSSQL触发器吗?

COMMENT TO PRESERVE FORMAT ON TRIGGER "DBA"."BATCH_DEDUCTIONS"."deductions_update" IS 
{create TRIGGER deductions_update AFTER UPDATE OF "FACTOR", "RATE"
ORDER 1 ON "DBA"."BATCH_DEDUCTIONS"
REFERENCING OLD AS old_row NEW AS new_row
FOR EACH ROW /* WHEN( search_condition ) */
BEGIN
    /* Type the trigger statements here */
    declare trfactor numeric(12,6);
    declare trrate numeric(12,6);
    declare tramount numeric(12,2);
    set trfactor = new_row.factor;
    set trrate = new_row.rate;
    set tramount = trfactor * trrate;
    update "dba"."batch_deductions" set amount = tramount 
        where batchno = new_row.batchno and empid = new_row.empid and item_no = new_row.item_no 
              and itemcode = new_row.itemcode
END
}
go

1 个答案:

答案 0 :(得分:0)

- 请参阅下面的代码 - 希望它可以帮到你.. ;

ALTER TRIGGER [dbo]。[deductions_update]    ON [dbo]。[BATCH_DEDUCTIONS]    更新后 如 开始      - 添加SET NOCOUNT ON以防止出现额外的结果集      - 干扰SELECT语句。     SET NOCOUNT ON;

declare @tramount numeric(12,2);

select @tramount = (new_row.factor * new_row.rate) from inserted new_row

IF (UPDATE(factor) OR UPDATE(rate))
BEGIN
    update batch_deductions set amount = @tramount
    from batch_deductions, inserted new_row 
    where batch_deductions.batchno = new_row.batchno and batch_deductions.empid = new_row.empid and batch_deductions.item_no = new_row.item_no 
          and batch_deductions.itemcode = new_row.itemcode
END

-- Insert statements for trigger here

END

GO