You need to sign in to do that
Don't have an account?
ccrawford
SOQL DATETIME comparisons
Hola,
I'm trying to do a simple query that compares two DATETIME fields on the same record. Here's the query:
SELECT Id FROM Lead WHERE AddressUpdated__c > AccountManagerUpdated__c
Both of these are custom fields (obviously) but I always get this error and for the life of me I can't figure out why:
MALFORMED_QUERY: ... unexpected token: AccountManagerUpdated__c
After much searching and doc flipping I can't seem to find anything that points at what I'm doing wrong...
I'm trying to do a simple query that compares two DATETIME fields on the same record. Here's the query:
SELECT Id FROM Lead WHERE AddressUpdated__c > AccountManagerUpdated__c
Both of these are custom fields (obviously) but I always get this error and for the life of me I can't figure out why:
MALFORMED_QUERY: ... unexpected token: AccountManagerUpdated__c
After much searching and doc flipping I can't seem to find anything that points at what I'm doing wrong...
Message Edited by ccrawford on 06-01-2007 09:30 PM
If you need to compare 2 fields like that, then you'd need to make a formula field does the comparision or returns the difference between the 2, so that in SOQL you can compare the formula result against a literal value.
Seems kinda silly, but I guess I can make *another* custom field. :)
- one date is determined outside the query, and
- one is a date field of the object
I used Dynamic SOQL (which means the query is evaluated at run time, not at save (&compile) time.I came up with this after I realized the reason binding with a date doesn't work.
It's that dates are converted to strings, sometimes as so 2008-3-2 (2nd March, 2008).
SOQL would insists the same date to be 2008-03-02. (double digits days, months)
Please notice 3 things in the code (highlighted bold)
LastModifiedDate!=CreatedDate
Because of this very strange limitation I can't do it in 5 mins. Unbelievable. I think this should be fixed in a subsequent release.
Indeed, SOQL is disappointingly weak when you try and do anything a little creative.
You can use the Excel Connector , or the Data Export tool, find the records you want and delete them.
I hope this helps.
Good luck getting SF to fix this, if you look at the upcoming ideas, you'll see that they are not really interested.
https://nextgensalesforce.wordpress.com/2015/11/30/dynamic-soql-query-results-in-local-time/