改为这样,不出错了,但没有得到我要的效果
select
case len(count(id)+1)
   when 1 then '0'+CONVERT(char(1), count(id)+1)
   else count(id)+1
   end 
   from teams where title=13

解决方案 »

  1.   


    select right('0'+cast(count(id)+1 as varchar(2)),2)
    from teams 
    where title=13
      

  2.   

    select
    case len(count(id)+1)
       when 1 then '0'+char(count(id)+1)
       else char(count(id)+1)
       end 
       from teams where title=13
      

  3.   

    select
    case len(count(id)+1)
       when 1 then '0' + CONVERT(char(1), count(id)+1)
       else str(count(id)+1)
       end 
       from teams where title=13
      

  4.   

    create table tb(a int)
    insert tb values (1)
    insert tb values (12)
    insert tb values (123)select
    a = case when len(a)<=2
         then right('0'+cast(a as varchar(10)),2)
       else convert(varchar(10),a)
       end
       from tb
    group by a/*  victorycyz(中海)写的这个对于多余2位的就不适合
    select a= right('0'+cast(a as varchar(10)),2)
    from tb 
    */drop table tb