sql 语句 begin end

--修改触发器,触发条件为--insert语句。
--触发的列为 [dbo].[trig_inGoods] 表 [dbo].[tb_InStore]
ALTER TRIGGER [dbo].[trig_inGoods] ON [dbo].[tb_InStore]
FOR insert

-----判断条件1
if exists(select GoodsID from inserted
where GoodsID in(select GoodsID from tb_GoodsInfo))
-----满足条件1,执行下面的语句
begin
-----判断条件2
if exists(select StoreName from inserted
where StoreName in(select StoreName from tb_GoodsInfo))
-----满足条件2执行下面的语句
begin
update tb_GoodsInfo set GoodsNum=GoodsNum+(select GoodsNum
from inserted) where GoodsID=(select GoodsID from inserted)
and GoodsName=(select GoodsName from inserted) and StoreName=(
select StoreName from inserted) and GoodsSpec=(
select GoodsSpec from inserted)
end
-----满足条件1,不满足条件2
else
-----执行 满足条件1,不满足条件2 的语句
begin
insert into tb_GoodsInfo(GoodsID,GoodsName,StoreName,GoodsSpec,
GoodsUnit,GoodsNum,GoodsInPrice,GoodsOutPrice)
select GoodsID,GoodsName,StoreName,GoodsSpec,GoodsUnit,
GoodsNum,GoodsPrice,GoodsPrice*110/100 from inserted
end
end
------不满足条件1,执行的语句
else
begin
insert into tb_GoodsInfo(GoodsID,GoodsName,StoreName,GoodsSpec,
GoodsUnit,GoodsNum,GoodsInPrice,GoodsOutPrice)
select GoodsID,GoodsName,StoreName,GoodsSpec,GoodsUnit,
GoodsNum,GoodsPrice,GoodsPrice*110/100 from inserted
end

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值