Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If there is a list of range specified like 2.000-3.000 , 3.001-4.000 , 4.000-5.001
and I want to find that 3.2 lies within which range using a SOQL Query . Can you pls suggest a SOQL Query regarding this

share|improve this question
Is it a string '2.000-3.000' ? – Sergey Utko Dec 6 '12 at 7:52
I think you may need to be more specific. Do you want to query for all records with a field in a set of ranges, or do you want to identify in which range a given values is ? To me the latter is probably something you would do in Apex, not SOQL. – Samuel De Rycke Dec 6 '12 at 8:28

You can't determine which range via a SOQL query - all you can do is determine that it falls into one of the ranges (building a dynamic SOQL query) and then post-process the results to figure out the exact range. You could determine which records fall into each range using dynamic SOQL and then post process these using Apex.

However, if the ranges are static I'd look at specifying a formula field that calculates the range dynamically:

IF (AND(MyVal__c>2.000, MyVal__c<=3.000),
    AND(MyVal__c>3.0001, MyVal__c<=4.000),

Then you can simply query back the calculated range for each record.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.