当前位置: 代码迷 >> Sql Server >> 求一条简单SQL语句,该如何解决
  详细解决方案

求一条简单SQL语句,该如何解决

热度:55   发布时间:2016-04-27 16:41:38.0
求一条简单SQL语句
判断删除物料编号时判断     当该物料的库存大于0或者有出入库记录时,不能删除。怎么判断?

if   not   exists(select   a.Num   from   Store   a  
left   join   InStockSub   b   on   b.Num=a.Num
left   join   OutStockSub   c   on   c.Num=a.Num
where   [email protected]     and   (a.Qty> 0   or   b.Num   is   not   null   or   c.Num   is   not   null))

这句话怎么改才合适?

------解决方案--------------------
if exists(select 1 from Store where [email protected] and qty> 0)
or exists(select 1 from InStockSub where [email protected])
or exists(select 1 from OutStockSub where [email protected])
begin
raiserror( '该物料有库存或有出入库记录,不能删除! ',16,1)
rollback tran
return
end
  相关解决方案