日期:2014-05-18 浏览次数:20660 次
create trigger alter_table on table stock for insert as declare @productname varchar(50) declare @Companyname varchar(50) declare @number int declare @type varchar(50) declare @sql varchar(4000) declare c_cur cursor for select productname,Companyname,Number,Type from inserted open c_cur fetch next from c_cur into @productname,@Companyname,@number,@type while @@fetch_status=0 begin if not exists( select * from Total where productname=@productname and Companyname=@Companyname) begin insert into Total(productname,Companyname) values(@productname,@Companyname) end update Total set Stocknumber=(case when @type='进货信息' then @number else 0 end), set Stock_back=(case when @type='进货退货信息' then @number else 0 end), set Sellnumber=(case when @type='销售信息' then @number else 0 end), set Sell_back=(case when @type='销售退货信息' then @number else 0 end) where productname=@productname and Companyname=@Companyname) fetch next from c_cur into @productname,@Companyname,@number,@type end close c_cur deallocate c_cur