Results 1 to 6 of 6

Thread: SQL Command for ranges

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    1

    SQL Command for ranges

    hello everyone.. i apologize if there have been other entries like this but i just had to this last minute thing and microsoft access and vb6 is killing me right now..

    so i have a table with a "minimum", "maximum", and "amount" field all set to number data type, double, fixed, and 2 decimal places

    in my program i have a textbox that contains a certain value.. once i click the button it is supposed to search the database for where the value on the textbox is in between the minimum and the maximum..

    E.G.

    minimum maximum amount
    0.00 499.00 100.00
    500.00 599.00 200.00
    600.00 699.00 300.00

    text1.text = 555.00

    what is the most appropriate sql for this so i get the 200.00 amount needed
    since 555.00 is in between 500.00 and 599.00

    i am sooo looking forward to an answer.. thank you sooo much in advance to whoever helps out.

  2. #2
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: SQL Command for ranges

    Dunno

    Code:
    select Amount
    From SomeTable
    Where (text1 >= [minimum]) AND (text1 <= [maximum])
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL Command for ranges

    Welcome to VBForums

    Thread moved to 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: SQL Command for ranges

    Reply in SQL server you could use a case statement. I am not familiar enough with access to know if this syntax will work, but you could give it a try:
    Code:
    declare @input money; set @input = 555.00
    
    select
    	case 
    		when @input between 0.00 and 499.00 then 100.00
    		when @input between 500.00 and 599.00 then 200.00
    	    when @input between 600.00 and 699.00 then 300.00
    	end
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: SQL Command for ranges

    pifft! No need for the select... the ranges are in a table, right?

    Code:
    SELECT * FROM tblRanges WHERE @Input BETWEEN MinField and MaxField
    Of course replace @Input with what ever means to get your value into it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: SQL Command for ranges

    of course Technome is right. i created a table and tested it
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

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