为了系统的直观,我选择了一个自定义项作为包装,因为系统内的换算率不是一直可以看到,而且称呼不直观。
大体用了两个触发器就可以搞定了。
--FOR ADD THE NEW GOODS
if exists (
select name from sysobjects
where xtype='TR' AND NAME='tri_pack_inventory')
drop trigger tri_pack_inventory
GO
CREATE TRIGGER tri_pack_inventory ON inventory FOR INSERT
AS
BEGIN
update inventory set cinvdefine11 = cast(right(cgroupcode,4) as int)
where cinvcode in (select cinvcode from inserted)
END
GO
--FOR UPDATE THE GOODS
if exists (
select name from sysobjects
where xtype='TR' AND NAME='tri_pack_update_inventory')
drop trigger tri_pack_update_inventory
GO
CREATE TRIGGER tri_pack_update_inventory ON inventory FOR UPDATE
AS
IF UPDATE (cgroupcode)
BEGIN
update inventory set cinvdefine11 = cast(right(cgroupcode,4) as int)
where cinvcode in (select cinvcode from inserted)
END
GO