GO
DECLARE @i CHAR(3)
DECLARE @b INT
SET @b = 1
WHILE (@b < 1000)
BEGIN
IF(LEN(CAST(@b AS CHAR)) < 2)
BEGIN
SELECT @i = '00' + CAST(@b AS CHAR)
INSERT INTO ticket (num) VALUES (@i)
END
ELSE IF(LEN(CAST(@b AS CHAR)) < 3)
BEGIN
SELECT @i = '0' + cast(@b AS CHAR)
INSERT INTO ticket (num) VALUES (@i)
END
ELSE
BEGIN
INSERT INTO ticket (num) VALUES (CAST(@b AS CHAR))
END
set @b=@b+1
END
GO