Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Posts
    3

    Unanswered: select between range

    Hi, I would like to run a select statement that figure out which value is closest. My table looks like this:
    VALUE
    100
    200
    300
    400
    and I can have a input like 257. Anyone know how I can get the nearest value, in this case 300?? thanks

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    What about this draft:

    create table test(value int)
    go
    insert test values(10)
    insert test values(15)
    insert test values(20)
    insert test values(40)
    go
    declare @num int
    set @num=23
    select top 1 *
    from test
    order by abs(value-@num)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •