declare @vorder varchar(15)
set @vorder = 'HQP00001'
declare @MaxID  varchar(10)
declare @Max  int
declare @Month  varchar(15)--/*
--產生新的出庫單號
set @Month=right(month(getdate()),1)
if month(getdate())=11
set @Month='A'
if month(getdate())=12
set @Month='B'
select  @MaxID=right(order_no,4),@Max=right(order_no,4)  from ordhead Where left(order_no,5) = @DisID+right(year(getdate()),2)+@Month
if @MaxID is not null
begin
set  @Max =  Right('0000'+Rtrim(@Max +1),4)
set  @MaxID =  @DisID+right(year(getdate()),2)+@Month+convert(varchar(4),@Max)
print @MaxID
print @Max
endif @MaxID is null
begin
set @MaxID =  @DisID+right(year(getdate()),2)+@Month+'0001'
print @MaxID
print @Max
end如上所述
print @Max 时显示的是2,我想要的是0002,当原来=0009时新的是0010
想要实现这样的效果
请告诉我这一句怎么修改set  @Max =  Right('0000'+Rtrim(@Max +1),4)
或者数据类型怎么重新定义

解决方案 »

  1.   

    declare @Max  int
    -->
    declare @Max  vatchar(10)set  @Max =  Right('0000'+Rtrim(@Max +1),4)
    -->
    set  @Max =  Right('0000'+Rtrim(cast(@Max as int) +1),4)
      

  2.   

    笔误declare @Max  int
    -->
    declare @Max  varchar(10)set  @Max =  Right('0000'+Rtrim(@Max +1),4)
    -->
    set  @Max =  Right('0000'+Rtrim(cast(@Max as int) +1),4)
      

  3.   

    用下CAST函数或者CONVERT函数啦。
      

  4.   

    set @max=right((10000+rtrim(@max+1)),4)