• Hi,

    There's no need for a loop. You just need to use a Tally Table. To know what it is and how it replaces a loop, read the following: http://www.sqlservercentral.com/articles/T-SQL/62867/

    With your tally table, your code would end like this:

    INSERT INTO BC

    SELECT '001',

    'teste',

    RIGHT( '000' + CAST( n AS varchar(4)), 4)

    FROM dbo.Tally

    WHERE n <= 9999

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2