当前位置: 代码迷 >> Sql Server >> 字符串添1
  详细解决方案

字符串添1

热度:73   发布时间:2016-04-24 22:42:23.0
字符串加1?
declare @maxcode char(3)
set @maxcode='015'
set @maxcode =@maxcode +1 
select @maxcode 


结果为 '16'
怎么转换为字符串'016'

------解决方案--------------------

declare @maxcode char(3)
set @maxcode='015'
set @maxcode='0'+convert(varchar,CAST(@maxcode as int)+1) 
select @maxcode

------解决方案--------------------

 declare @maxcode varchar(3)
 set @maxcode='015'
 set @maxcode =cast(cast(@maxcode as int) +1 as varchar(3))
 select right('0000'+@maxcode,3)
  相关解决方案