If you have a column, of data type = INT, with the following numbers as separate rows. 1 3 4 5 7 10 How can you write a t-sql statement where you can calculate the nearest number to any give input. Example , if the input is 9 ? (the answer is 10) If the input is 8 (the anwer is 7) The following 2 solutions will work --1 SELECT c1 FROM @t WHERE ABS(c1 - @yourVar) = (SELECT MIN(ABS(c1 - @yourVar))FROM @t); 2)SELECT TOP 1 c1 FROM @t ORDER BY ABS(c1-@yourVar) Related Posts T-SQL UPDATE JOIN on a table... Read more →