+ Start a Discussion
crowcoder@gmail.comcrowcoder@gmail.com 

Spot my SOQL error?

I'm new to SOQL, not at all new to SQL.

 

My error is - 19:54:07:150 FATAL_ERROR System.QueryException: unexpected token: AND

 

with this query:

SELECT
Id,
Name,
Shipper_Name__c,
Service__c,
Dispatch_Date__c,
Start_Time__c,
End_Time__c
FROM
Dispatch__c
WHERE
Shipper_LastName__c like '%load%'
OR Phone_1__c = 'load'
OR Phone_2__c = 'load'
OR GBL__c = 'load'
OR SIT__c = 'load'
OR SO__c = 'load'
OR REF__c = 'load'
OR BOL__c = 'load'
OR Service__c = 'load'
AND ( Dispatch_Date__c >= 2012-12-17 AND Dispatch_Date__c <= 2012-12-31 )
ORDER BY
Dispatch_Date__c DESC

 

But this works:

SELECT
Id,
Name,
Shipper_Name__c,
Service__c,
Dispatch_Date__c,
Start_Time__c,
End_Time__c
FROM
Dispatch__c
WHERE
 Dispatch_Date__c >= 2012-12-17 AND Dispatch_Date__c <= 2012-12-31 
ORDER BY
Dispatch_Date__c DESC

Best Answer chosen by Admin (Salesforce Developers) 
Suresh RaghuramSuresh Raghuram

SELECT
Id,
Name,
Shipper_Name__c,
Service__c,
Dispatch_Date__c,
Start_Time__c,
End_Time__c
FROM
Dispatch__c
WHERE
 ( Dispatch_Date__c >= 2012-12-17 AND Dispatch_Date__c <= 2012-12-31 ) AND(Shipper_LastName__c like '%load%'
OR Phone_1__c = 'load'
OR Phone_2__c = 'load'
OR GBL__c = 'load'
OR SIT__c = 'load'
OR SO__c = 'load'
OR REF__c = 'load'
OR BOL__c = 'load'
OR Service__c = 'load')
ORDER BY
Dispatch_Date__c DESC