日期:2014-05-18  浏览次数:20391 次

求一条简单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   a.Num=@Num     and   (a.Qty> 0   or   b.Num   is   not   null   or   c.Num   is   not   null))

这句话怎么改才合适?

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