I have a table that has a 'location' field that ranges from 1 to 25. I use the following SQL to currently return the lowest 'location' that is currently unused;
select top 1 field from [dbo].[misc_fields] where field NOT IN (select location from ListFields where listid = @listid) order by field
The problem with this is that it is reliant on the misc_fields table which contains a row for each location (1-25). I would like to remove the need to have this lookup table and just define the range within the Stored Procedure itself.