把上面的循环部分改成:
insert into @tb select right('000000'+cast(cast(@counter +1) as varchar),6),lower(left(newid(),6))
set @counter=@counter+1

解决方案 »

  1.   

    declare @tb table (id int identity,b char(6))set rowcount 1000
    insert @tb(b) select lower(left(newid(),6))
    from syscolumns a,syscolumns binsert into t_0216user (fuser,fpass)
    select right(1000000+id,6),b from @tb
      

  2.   

    改成:
    insert into @tb select right('000000'+cast(@counter+1 as varchar),6),lower(left(newid(),6))
    set @counter=@counter+1
      

  3.   

    --如果楼主喜欢用循环(效率比我的低)declare @tb table (a char(6),b char(6))
    declare @counter int
    set @counter=0
    while @counter<1000
    begin 
    set @counter=@counter+1
    insert into @tb select right(1000000+@counter,6),lower(left(newid(),6))
     
    end
    insert into t_0216user (fuser,fpass) select a,b from @tb
      

  4.   

    declare @tb table (a char(6),b char(6))
    declare @counter int,@id int
    select @counter=0,@id=0
    while @id<1000
    begin 
    set @counter=@counter+1
    if charindex('4',@counter)=0
    begin
    set @id=@id+1
    insert into @tb select right(1000000+@counter,6),lower(left(newid(),6))
    end 
    end
    insert into t_0216user (fuser,fpass) select a,b from @tb