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
Hari G SHari G S 

Concatinate function in SOQL

 

Hi,

 

What should be the query to cancatinate two fields in SOQL

 

The equivalent mysql query is

select id from User where concat(firstname," ",lastname)="Hari G S";

 

Thanks and Regards

Hari G S

Best Answer chosen by Admin (Salesforce Developers) 
hchhch

There is nothing like concat function in SOQL.

If you are querying on the user object to retrieve the first name and last name values by appending, then you can use the standard name field on user. The query looks like this:

User u = [select id, name from user where name='hari gs'];

All Answers

raseshtcsraseshtcs

Use this way:

 

soql='SELECT Id,Name,Alias_Company_Name__c,Office_Country__c, Office_State__c, Prospect_Of__c,Client_Of__c FROM Account where Name != null';

//Some Code...

 

soql+= 'order by '+ sortfield + ' ' + sortDir;

 

then use

results = Database.query(soql);


 

raseshtcsraseshtcs

sortfield is a variable defined in the controller...

Hari G SHari G S

 

Thanks for the reply.

 

But i actualy want to know whether there is any function like concat in SOQL to concatinate two fields, not appending query string using + operator.

 

In user object we have fields firstname and lastname. firstname is hari and lastname is gs. I want to check whether  hari gs is present in the user object combining these two fields. The logic in mysql query is below

 

select id from user where concat(firstname," ",lastname)="hari gs";

 

Regards

Hari

hchhch

There is nothing like concat function in SOQL.

If you are querying on the user object to retrieve the first name and last name values by appending, then you can use the standard name field on user. The query looks like this:

User u = [select id, name from user where name='hari gs'];

This was selected as the best answer