Find closest numeric value in database

get the difference between the area and your input, take absolute value so always positive, then order ascending and take the first one

SELECT TOP 1 * FROM [myTable] 
WHERE Name="Test" and Size = 2 and PType="p"
ORDER BY ABS( Area - @input ) 

Leave a Comment