I need some ideas, I have a MasterObject which has zip code information.

Table structure is:

zipcode Text(5)
Minzip Text(4)
Maxzip Text(4)
CountName Text(25)

Zipcode Minzip Maxzip CountyName
98052 1000 2000 Orange County
98052 2001 3000 Deleware County
98053 1000 3000 Franklin County

if user enters 98052-1821. There are two row for 98052 but 1821 range falls between Minzip: 1000 and Maxzip: 2000.

i need to get the Orange country information. Is is possibel to write a SOQL query for this condition.

for Ex: SELECT Id, CountyName__c from MasterObject Where Zipcode = '98052' and (Minzip > '1821' and Maxzip < '1821') this is the logic i am expecting.

  • Why not Franklin County? There is some overlap... pretty unclear how you would handle collision behavior but regardless you will need to query all candidate MasterObject records and then use some Apex to select the correct one (if any). Likely not possible just with SOQL.
    – Adrian Larson
    May 6 '15 at 17:37
  • Hi Adrian, 1821 falls in Min and Max range of first row. Its basically we want to minimize the total number of rows for zip info for that we are using Min Max option.
    – Tamil
    May 6 '15 at 17:47
  • You're missing my point, 1821 also falls between 1000 and 3000. You're also going to have problems with, for instance, 'a' > '1821', so you need apex for stronger typing.
    – Adrian Larson
    May 6 '15 at 17:50
  • In my example I have mentioned Zipcode = '98052' I have updated my question.
    – Tamil
    May 6 '15 at 17:58

Yes, you should be able to use comparison operators in your soql SELECT statement. Refer here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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