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



我的任务是将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

-请参阅下面的代码--希望它能帮助你。。;

ALTER触发器[dbo]。[扣除_更新]ON[dbo]。[批次导出]更新后作为开始--添加SET NOCOUNT ON以防止额外的结果集--干扰SELECT语句。设置NOCOUNT;

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

结束

GO

最新更新