declare @Sum int, @OneInputNum int,@OneOutSum int,@BH varchar(50),@i int -- @BH:入库时的物品编号
set @i=0select top 1 @OneInputNum=RK_SL, @BH=RK_BH from TB_CCGL_XX where RK_Type=@type and RK_PM=@PM and RK_SL>0 and ID not in (select top 1*@i RK_SL from TB_CCGL_XX where RK_Type=@type and RK_PM=@PM and RK_SL>0 order by ID) order by ID
报错说在@i附近有错误

解决方案 »

  1.   

    select top 1 @OneInputNum=RK_SL, @BH=RK_BH from TB_CCGL_XX 
    where RK_Type=@type and RK_PM=@PM and RK_SL>0 
    and ID not in (select top (@i)--加括号
     RK_SL from TB_CCGL_XX where RK_Type=@type and RK_PM=@PM and RK_SL>0 order by ID) order by ID  
      

  2.   

    select top 1 @OneInputNum=RK_SL, @BH=RK_BH from TB_CCGL_XX 
    where RK_Type=@type and RK_PM=@PM and RK_SL>0 
    and ID not in (select top ('+ltrim(@i)+')--加括号
     RK_SL from TB_CCGL_XX where RK_Type=@type and RK_PM=@PM and RK_SL>0 order by ID) order by ID  
    --或者这样
      

  3.   

    select top (1*@i)2000用动态。