function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sudhirn@merunetworks.comsudhirn@merunetworks.com 

SOQL between condition

Hi, 

 We have a custom object with name Territory_Lookup__c field inside this object are name, zip_start, zip_end

We have values inside this table like 
  
 Name     Zip_Start  Zip_End
 APAC           1         10
 NAM             11        20

If we pass 2 to soql it must APAC if user pass 12 it must show NAM
 
I tried below query its not working Please suggest me how to modify the query

SELECT name,zip_start,zip_end FROM territory_lookup__c where Zip_Start__c >= 2  or   Zip_End__c <=2 

Thanks
Sudhir
Best Answer chosen by sudhirn@merunetworks.com
ArmouryArmoury
Try this.. 
SELECT name,zip_start,zip_end FROM territory_lookup__c where Zip_Start__c <=2 AND Zip_End__c >=2

All Answers

ArmouryArmoury
Try this.. 
SELECT name,zip_start,zip_end FROM territory_lookup__c where Zip_Start__c <=2 AND Zip_End__c >=2
This was selected as the best answer
Mangesh Pawar 30Mangesh Pawar 30

I have similar use case but instead of numbers I have canada zip codes which are combination of alphanumeric characters.

We have values inside this table like 
  
 CarId          Zip_From              Zip_To
 1000          N3W 0A0              N4J 9Z9
 2000          P0A 0A0               P0G 9Z9

The query should return CarId = 1000 if input zip code = 'N3W 1A1'

SOQL doesn't support between clause, then how can I compare the string format input zipcode is falling in the range or not?