Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
matt_calhoon
Posting Yak Master
235 Posts |
Posted - 2002-02-22 : 22:28:30
|
| Hi there,Is there a sql function/command that will return a number that is closest to another number, whether that number is greater or less than the number concerned? For eg;I want to return the number nearest to 150.the result list:120180155so 155 will be returned as it is closest to the 150 number?Thanks - matt |
|
|
jbkayne
Posting Yak Master
100 Posts |
Posted - 2002-02-23 : 01:31:31
|
| I would just use the following:select top 1 Number from Listorder by abs(Number - @number) |
 |
|
|
matt_calhoon
Posting Yak Master
235 Posts |
Posted - 2002-02-23 : 18:52:00
|
| exactly what I was looking for.thanks jbkayne. |
 |
|
|
|
|
|