You need to sign in to do that
Don't have an account?
Andrew McGrath
SOQL - Developer Console - NOT NULL operator
Hi
Been looking around with no luck - is there a simple equivalent to the SQL not null statement in SOQL (ie return rows where the column contains a value?)
Current query:
SELECT Id, Name, customfield__c from Account
Where customfield__c !=null
Any help greatly appreciated! I feel the answer is obvious but it is driving me mad.
Cheers
Been looking around with no luck - is there a simple equivalent to the SQL not null statement in SOQL (ie return rows where the column contains a value?)
Current query:
SELECT Id, Name, customfield__c from Account
Where customfield__c !=null
Any help greatly appreciated! I feel the answer is obvious but it is driving me mad.
Cheers
For example, if u have two contacts:
Contact1(FirstName = null, LastName = 'First')
Contact2(FirstName = 'Junk', LastName = 'Second')
Thanks,
Alex
All Answers
Hi Andrew,
Yes, your query is correct, for filter not null value use "!= null"
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
For example, if u have two contacts:
Contact1(FirstName = null, LastName = 'First')
Contact2(FirstName = 'Junk', LastName = 'Second')
Thanks,
Alex
I have around 12 fields. Trying to write a SOQL query for more than one field to exclude null values.
For single field which is not null, I am able to get the records. I want to a SOQL to get the records for all 12 fields which are not null.
Below is the SOQL to get the records for single field which is not null:
SELECT Name ,AccountNumber, OwnerId,ParentId, Data_Center_BDE__c,Tele_CDE__c,DMS_Owner__c,Primary_Local_Market_Rep_1__c,Information_Governance_Rep__c,DM_Cloud_Sales_Rep__c,Primary_BDE__c,Primary_CDE__c,Primary_BDE_DB_R__c,Primary_CDE_DB_R__c,Library_Services_BDE__c FROM Account WHERE Data_Center_BDE__c != NULL
similarly I want to write for other 12 fields which are not null. Can you please suggest.
In soql, there is no shortcut, if you have to check if 12 fields are not null you need to mention all 12 fields like below.
[SELECT name, rating,industry, phone, Number__c FROM account WHERE (rating!=null and industry!=null and phone!=null and name!=null and Number__c!=null)]
//i just mentioned 5 fields. However, if you have to mention 12 fields, add upto 12 in the same way.
Thanks, Manu, Below query is working for my question.
SELECT Name ,AccountNumber, OwnerId,ParentId, Data_Center_BDE__c,Tele_CDE__c,DMS_Owner__c,Primary_Local_Market_Rep_1__c,Information_Governance_Rep__c,DM_Cloud_Sales_Rep__c,Primary_BDE__c,Primary_CDE__c,Primary_BDE_DB_R__c,Primary_CDE_DB_R__c,Library_Services_BDE__c FROM Account where Data_Center_BDE__c != NULL and Tele_CDE__c != NULL and DMS_Owner__c != NULL and Primary_Local_Market_Rep_1__c != NULL and Information_Governance_Rep__c != NULL and DM_Cloud_Sales_Rep__c != NULL and Primary_BDE__c != NULL and Primary_CDE__c != NULL and Primary_BDE_DB_R__c != NULL and Primary_CDE_DB_R__c != NULL and Library_Services_BDE__c != NULL