At times you may need a zero as a prefix to sequential numbers
ie:
00001
00002..
00009
00010…
Here is test code that flows through one to ten thousand:
declare @number int,@prefix varchar(20),@display_number varchar(20)-----------------------------set @number=0while @number<10000beginset @number=coalesce(@number, 0)-----------------------------if len(convert(varchar(20), @number))>0and @number<>0begin-- ones placeif len(convert(varchar(20), @number))=1beginset @display_number='0000'+convert(varchar(20), @number)print @display_numberend-- tens placeif len(convert(varchar(20), @number))=2beginset @display_number='000'+convert(varchar(20), @number)print @display_numberend-- hundreds placeif len(convert(varchar(20), @number))=3beginset @display_number='00'+convert(varchar(20), @number)print @display_numberend-- thousands placeif len(convert(varchar(20), @number))=4beginset @display_number='0'+convert(varchar(20), @number)print @display_numberendendset @number=@number+1end
No comments:
Post a Comment