How can I write a single select statement that does the following:
I have an integer column in my table and i want to find the minimum available (non-used) value in that column where the value is below 1000 and also where the value does not exist in TableB Column1
Thanks
Similar to LukeH’s answer but it does what you asked for:
Edit:
And pick the minumum of the two values.
It still needs checking if the value 1 is available, but if you have a gap between A and B it should find A+1 and B-1 now and you could pick the smallest. Obviously A+1 is the smallest so you can just use the second part…