• This is just a guess on what you might be trying to do, just a lot simpler and (hopefully) faster.

    It inserts everything at once instead of going one item at a time.

    INSERT ChestItems

    SELECT c.ChestID

    ,i.ItemID

    FROM Chests c

    CROSS APPLY (SELECT TOP ((ABS(CHECKSUM(NEWID())) % (c.ChestTier * 2)) + 1)

    Items.ItemID

    FROM Items

    WHERE Items.ItemTier = Chests.ChestTier) i

    WHERE c.ChestID <= 1000

    It might not work as you need, but it's an example of how you could do it.

    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