declare @sort_id int
select @sort_id=10
select @sort_id=20 from sysobjects where 1=2
select @sort_id
你认为@sort_id是多少?
是 10,20 还是 NULL
对,不是null,那么以下程序就隐含了错误:
select top 1 @sort_id=c_sort from tb_o_wg (nolock) where c_id=@id and c_adno=@adno
if isnull(@sort_id,0) = 0
begin
select @msg = '本单有商品部门为限制部门,序号'+rtrim(ltrim(str(@sort_id)))+'!'
raiserror 99999 @msg
return(-1)
end
select top 1 @sort_id=c_sort from tb_o_wg (nolock) where c_id=@id and isnull(c_pt_cost,0)=0
if isnull(@sort_id,0) > 0
begin
select @msg = '本单有无成本的商品,序号'+rtrim(ltrim(str(@sort_id)))+'!'
raiserror 99999 @msg
return(-1)
end
应注意避免这种隐藏较深的逻辑错误