首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

为什么 微软 sql 语句 用 begin end 恩解决办法

2012-03-29 
为什么 微软 sql语句 用 beginend 恩为什么 微软 sql语句 用 beginend 恩--修改触发器,触发条件为--insert

为什么 微软 sql 语句 用 begin end 恩
为什么 微软 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

[解决办法]
程序代码的开始与结束.用begin和end最准确.我感觉.

热点排行