• I suggest creating another table containing every possible 3-char value, clustered on that code (fillfactor 100). Then join to that table and find the first one that isn't in use.

    OR

    If you (almost) never delete rows where you're adding the 3-char code, delete each 3-char code from the lookup table as you insert it into the main/detail table. Then you would always just select the MIN(code3) from the lookup table.

    Scott Pletcher, SQL Server MVP 2008-2010