如果在触发器中有两个条件怎么写

来源:百度知道 编辑:UC知道 时间:2024/07/04 15:19:55
create trigger t_output on 商品情况表
for insert
as
if exists(select 商品代码 from inserted
where 商品代码 not in (select 商品代码 from 进货表))
or exists(select * from 商品情况表 where 库存量<=0)
begin
raiserror('商品不存在',16,1)
rollback transaction
else
begin
update 商品情况表
set 库存量=库存量-销售数量

end

销售数量是变量 库存量也是变量 怎么样写条件才对!
急急~~~~那哪位高人指点一下

create trigger t_output on 商品情况表
for insert
as
declare @kuncun int
declare @xiaoshou int--先定义2变量

if exists(select 商品代码 from inserted
where 商品代码 not in (select 商品代码 from 进货表))
or exists(select * from 商品情况表 where 库存量<=0)
begin
raiserror('商品不存在',16,1)
rollback transaction
else
begin
select @kuncun=kuncun,@xiaoshou=xiaoshou from inserted--从你刚才插入的信息中获取库存和销售的数量。。。下面写你的update语句就行了
update 商品情况表
set 库存量=库存量-销售数数量

end