CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2015
    Posts
    4

    get nearest or closest values

    In the access data table there are two fields:-
    name Value
    GS402 300
    GS632 600
    GS802 1000
    GS100 2000
    GS101 2000
    GS121 4000
    GS125 4000
    GS160 8000
    GS161 8000
    GS201 16000
    GS200 16000
    GS250 32000
    GS251 23600

    I am using Vb6 and access 2010 database

    if i get value 4800 then

    what query i should write in vb to get nearest or closest values of 4800 from the above table

    Please help me to to get the query
    Last edited by suraj14; May 4th, 2015 at 02:44 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: get nearest or closest values

    Query Analyzer should convert it to SQL for you. Try it out!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: get nearest or closest values

    Off the top of my head I would think this may be a case for a union
    http://www.w3schools.com/sql/sql_union.asp

    You could use that to execute two queries one to find the next highest value and the other to find the next lowest value and then compare those two values to your target value to see which is closest.
    Always use [code][/code] tags when posting code.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured