declare @Str varchar(25)
declare @Index int
declare @Diff int
set @Index=0
while(@Index<@Count) begin set @Diff=4-Len(@Index) set @Str='' while @Diff>0 begin set @Str=@Str+'0' set @Diff=@Diff-1 end set @Str=@Str+Str(@Index) set @Index=@Index+1 print @Str end