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

郁闷——存储过程问题
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

ALTER procedure p_packOut_check
@voucher varchar(32),@partcode varchar(18), @out_num decimal(10,2)
as
begin

declare @num decimal(10,2)
declare @price1 decimal(18,5)
declare @fax decimal(18,5)
declare @price2 decimal(18,5)
declare @supply_id varchar(10)
declare @supply_cn varchar (15)
declare @raidno varchar (32)

while @out_num>0
begin
select top 1 @num=stock_num ,@price1=price1 ,@fax=fax ,@price2=price2 ,@raidno=raidno from pack_fix_in where stock_num>0 and partcode=@partcode order by in_date 
if @out_num<=@num
 begin
insert into pack_fix_out_details ([voucher], [raidno], [partcode], [partname], [parttype], [partunit], [partclass], [out_num], [out_date], [price1], [fax], [price2], [supply_id], [supply_cn], [hander], [maker], [makedate], [checker], [checkdate], [car_no], [cn], [notes])
select [voucher], [raidno], [partcode], [partname], [parttype], [partunit], [partclass], @out_num, [out_date],@price1, @fax, @price2, @supply_id,@supply_cn, [hander], [maker], [makedate], [checker], [checkdate], [car_no], [cn], [notes] from pack_fix_out
where voucher=@voucher and partcode=@partcode 
update pack_fix_in set stock_num=@num-@out_num where partcode=@partcode and raidno=@raidno
set @out_num=0
 end 
else 
 begin 
 insert into pack_fix_out_details ([voucher], [raidno], [partcode], [partname], [parttype], [partunit], [partclass], [out_num], [out_date], [price1], [fax], [price2], [supply_id], [supply_cn], [hander], [maker], [makedate], [checker], [checkdate], [car_no], [cn], [notes])
 select [voucher], [raidno], [partcode], [partname], [parttype], [partunit], [partclass], @num, [out_date],@price1, @fax, @price2, @supply_id,@supply_cn, [hander], [maker], [makedate], [checker], [checkdate], [car_no], [cn], [notes] from pack_fix_out
 where voucher=@voucher and partcode=@partcode 
 update pack_fix_in set stock_num=0 where partcode=@partcode and raidno=@raidno
 set @out_num=@out_num-@num
 end 
end 

 
end

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


EXEC [GR_Logistics].[dbo].[p_packOut_check] 'Jl201261601',' 020800700020',3.0
执行时 数据没进行操作


而我直接这样写 有没问题 为什么 ?? 
 declare @voucher varchar(32)
declare @partcode varchar(18) 
declare @out_num decimal(10,2)
set @voucher='Jl201261601' 
set @partcode='020800700020'
set @out_num='3'
 
begin
declare @num decimal(10,2)
declare @price1 decimal(18,5)
declare @fax decimal(18,5)
declare @price2 decimal(18,5)
declare @supply_id varchar(10)
declare @supply_cn varchar (15)
declare @raidno varchar (32)
while @out_num>0
begin
select top 1 @num=stock_num ,@price1=price1 ,@fax=fax ,@price2=price2 ,@raidno=raidno from pack_fix_in where stock_num>0 and partcode=@partcode order by in_date 
if @out_num<=@num
 begin
insert into pack_fix_out_details ([voucher], [raidno], [partcode], [partname], [parttype], [partunit], [partclass], [out_num], [out_date], [price1], [fax], [price2], [supply_id], [supply_cn], [hander], [maker], [makedate], [checker], [checkdate], [car_no], [cn], [notes])
select [voucher], [raidno], [partcode], [partname], [parttype], [partunit], [partclass], @out_num, [out_date],@price1, @fax, @price2, @supply_id,@supply_cn, [hander], [maker], [makedate], [checker], [checkdate], [car_no], [cn], [notes] from pack_fix_out
where voucher=@voucher and partcode=@partcode 
update pack_fix_in set stock_num=@num-@out_num where partcode=@partco