Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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' ? –  mast0r Dec 6 '12 at 7:52
1  
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
add comment

1 Answer

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),
    '2-3',
    AND(MyVal__c>3.0001, MyVal__c<=4.000),
    '3-4')

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

share|improve this answer
add comment

Your Answer

 
discard

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.