SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GOALTER   procedure p_packOut_check
@voucher varchar(32),@partcode varchar(18), @out_num decimal(10,2)
as
begindeclare @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  
endGO
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=@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

解决方案 »

  1.   

    [p_packOut_check] 'Jl201261601',' 020800700020',3.0
    直接执行这个呢 ?
      

  2.   

    EXEC [GR_Logistics].[dbo].[p_packOut_check] 'Jl201261601',' 020800700020',3.0
    执行时 数据没进行操作 
    而我直接这样写 又没问题 为什么 ??  
     declare @voucher varchar(32)
      

  3.   

    给你说个方法,
    你把存储过程的脚本先都注释掉,
    只执行部分字段,
    尝试 把每一步得到的值 select 或者 print 出来 ...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
    ---------------------------------------------------------------------------------节点1
    select 1
    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  
    ---------------------------------------------------------------------------------节点2
    /*
    --脚本每次运行一部分,查看在存储过程里面执行的每一步结果
    select @num,@price1,@fax,@price2,@raidno
    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