Find your content:

Search form

You are here

How to find if a value lies within a list of ranges specified

 
Share

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


Attribution to: divya

Possible Suggestion/Solution #1

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.


Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5118

My Block Status

My Block Content