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
RDN_LHRRDN_LHR 

Comparing dates in SOQL WHERE clause

I want to do the following query to find unread EmailMessage records related either to (1) open cases or (2) related to cases that were already closed when the EmailMessage record was created.

 

I would think it would be:

 

select id,ParentId, Parent.Owner.Name,Parent.IsClosed, Parent.ClosedDate,status,fromaddress,toaddress,messagedate,subject from emailMessage where status ='0' and (Parent.IsClosed = false or emailMessage.CreatedDate > Parent.ClosedDate)

 

I get "unexpected token: 'Parent.ClosedDate'"

 

Can I not compare one date to another using "greater-than"?

 

If I replace either Parent.ClosedDate or emailMessage.CreatedDate with something like LAST_WEEK then the query works but not comparing to each other.

 

Any help is appreciated!!

Message Edited by RDN_LHR on 06-08-2009 09:27 AM
RDN_LHRRDN_LHR
I was hoping somebody would know the answer to this. ..... anyone?? anyone??  :smileysurprised:
SuperfellSuperfell
You can't compare fields against other fields, only against literal values, or pseudo literal values (like LAST_WEEK)
RDN_LHRRDN_LHR

Thanks for the answer!!  Though honestly, I don't know whether to cry or laugh.

SuperfellSuperfell
In some cases you can build a formula field to do the diff between 2 dates, then in SOQL compare that formula field value against 0 (or some other offset).