Reputation: 17
I have a column in a table that is integers but not in any common increments like: 1, 20, 30, 33
I thought this would be easy but all I want is to write a query that will return the next number, like if my current number is 1 how do I return 20?
Upvotes: 1
Views: 1611
Reputation: 384
The simplest is to select to first Min value that is greater than the one you have:
SELECT TOP 1 MIN(col) FROM table where col > currentNumber
The issue you have is that this is not in any good context (e.g. what is currentNumber? A variable? from another table?)
Upvotes: 2
Reputation: 21620
I think you just want to select the next highest value... select column_name from table where column_name > current_value
Upvotes: 0