|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
使用了一个简单的例子。
/*
采购入库后立即生成材料出库单(子表)
@@naojin
*/
CREATE TRIGGER trigImmedRds ON [dbo].[RdRecords]
FOR INSERT --仅对insert进行触发,也可对update触发
AS
declare @MaxRdCode int, @MaxRdsCode int,@tmp int
declare @cInvCode varchar(20), @ssql varchar(1000)
declare @iQuantity float,@iUnitCost float,@iPrice float
--由插入采购入库单子表数据时触发
--如果不是采购入库的话就退出
--注意写法。inserted记录了已插入的数据
if not exists(select 1 from inserted rds
inner join rdrecord rd on rds.id=rd.id and rd.cVouchType='01' and rd.cWhCode='006')
return
select @MaxRdCode=iFatherId,@MaxRdsCode=iChildId+1 from ufsystem..ua_identity where cAcc_id='008' and cVouchType='rd'
insert into rdrecords(autoid,id,cInvCode,iNum,iQuantity,iUnitCost,iPrice,iFlag)
select @MaxRdsCode,@MaxRdCode,cInvcode,0,iQuantity,iUnitCost,iPrice,0
from inserted
select @iQuantity=iQuantity,@cInvCode=cInvCode from inserted
update ufsystem..ua_identity set iChildId=@MaxRdsCode where cAcc_id='008' and cVouchType='rd'
--更新现存量表
update currentstock set iQuantity=iQuantity-@iQuantity where cInvCode = @cInvCode and cWhcode in(select cWhcode from rdrecord where id=@MaxRdCode) |
|