You need to sign in to do that
Don't have an account?
MikeGill
MALFORM Query when trying to compare formula date fields
I am trying to perform a "not equal" on two date fields (formula derived)
select Id, MasterContract_Start_Date__c, Current_Contract_Start_Date__c from Asset where MasterContract_Start_Date__c != Current_Contract_Start_Date__c
I'm getting MALFORM query unexpected token when executing the above query using SoqlXplorer.
Compare to today works fine
select Id, MasterContract_Start_Date__c, Current_Contract_Start_Date__c from Asset where MasterContract_Start_Date__c != today
What am I doing wrong, I should be able to do this I would have thought?
Hi Mike,
Here the problem is not due to date type. It is in your where clause:
select Id, MasterContract_Start_Date__c, Current_Contract_Start_Date__c from Asset where MasterContract_Start_Date__c != Current_Contract_Start_Date__c
As far as I know the above query wouldn't work because Current_Contract_Start_Date__c is also a field of the Asset object and you have not fetched it yet. So it doesn't know what is the value of Current_Contract_Start_Date__c with which you are comparing MasterContract_Start_Date__c.
I am not sure if there is any other solution, but I suggest you try the following work around.
You can create a formula field on Asset, say CompareDates__c:
IF(MasterContract_Start_Date__c != Current_Contract_Start_Date__c, 'True', 'False')
Now you can modify your query as:
select Id, MasterContract_Start_Date__c, Current_Contract_Start_Date__c from Asset where CompareDates__c = 'True'
Hope this solves your problem. If so please mark it as solution so that others may benefit. Else let me know what went wrong.
Regards,
Lakshmi.
All Answers
Hi Mike,
It is possible that one of the arguments is date while the other is of type datetime. Please to check this aspect for finding the reason of failure. Also I would suggest that you run the same query in salesforce "syetem log" :-
Hope this helps.
Thanks for your response.
I have checked both fields are type date.
Running this in system log
Gives unexpected token too. Strange isn't it
Hi Mike,
Here the problem is not due to date type. It is in your where clause:
select Id, MasterContract_Start_Date__c, Current_Contract_Start_Date__c from Asset where MasterContract_Start_Date__c != Current_Contract_Start_Date__c
As far as I know the above query wouldn't work because Current_Contract_Start_Date__c is also a field of the Asset object and you have not fetched it yet. So it doesn't know what is the value of Current_Contract_Start_Date__c with which you are comparing MasterContract_Start_Date__c.
I am not sure if there is any other solution, but I suggest you try the following work around.
You can create a formula field on Asset, say CompareDates__c:
IF(MasterContract_Start_Date__c != Current_Contract_Start_Date__c, 'True', 'False')
Now you can modify your query as:
select Id, MasterContract_Start_Date__c, Current_Contract_Start_Date__c from Asset where CompareDates__c = 'True'
Hope this solves your problem. If so please mark it as solution so that others may benefit. Else let me know what went wrong.
Regards,
Lakshmi.
Thanks Lakshmi - that makes sense now
Good call with the formula field.