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

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

2012-02-01 
求一条简单SQL语句判断删除物料编号时判断当该物料的库存大于0或者有出入库记录时,不能删除。怎么判断?ifno

求一条简单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

热点排行