I have a SQL Record that has number that are all out of order (has gaps) for example: 1,2,3,7,9,11…..
I would like to get only the first missing number.
I tried something like this but I just don’t know SQL to make it work correctly.
strQuery = "SELECT N as NextNum FROM LOADS WHERE N > 0 AND N <= (SELECT MAX(LOAD_NO) FROM @LOADS) AND N NOT IN (SELECT LOAD_NO FROM @LOADS)"
objNextNum.Open strQuery
lastLoadNo= objNextNum("NextNum")
response.write "NEXT LOAD NUMBER IS: " & lastLoadNo
I found that example on a ms website but I cannot get it to work.
Thanks for any help!!!
saw this somewhere, can’t remember where though, or i’d give proper attribution, but you should be able to use this: