+ Start a Discussion
Anto HotelbedsAnto Hotelbeds 

SOQL LIKE comparisson

Hi,

When creating a lead, I need to compare the lead Fiscal number field with the account fiscal number in a soql query. 
The issue comes with this case:
Lead Fiscal Number: DE12345
Account Fiscal Number: 12345

I want the query to detect this situation and return me the account in the list, but it doesnt appear:

This is my code:

        string FiscalNumber1Lead='%' + lead.Fiscal_Number_1__c + '%';
      
        return [Select ID, Name, Owner.Name, Fiscal_Number_2__c, Fiscal_Number_1__c,KAM__c,AccountNumber,Account_Status__c,Commercial_Brand__c, Inactive_Reason__c From Account
        Where ((Fiscal_Number_1__c LIKE :FiscalNumber1Lead))  limit 100];

But with this situation I am comparing  '12345' like: '%DE12345%', and obviously returns me no results....

I also tried to change the condition to:

Where ((l2.Fiscal_Number_1__c LIKE :Fiscal_Number_1__c)) but it returns me an error in the code.

Can anybody give help me please?

Thanks,

Antonio
MagulanDuraipandianMagulanDuraipandian
string FiscalNumber1Lead='%\'' + lead.Fiscal_Number_1__c + '%\'';

Try this!

If this solves your problem, kindly mark it as the best answer.

Regards,
Magulan
http://www.infallibletechie.com
Anto HotelbedsAnto Hotelbeds
Hi,
Thanks for your help but then I would be comparing lead fiscal number with lead fiscal number,....
dev_sfdc1dev_sfdc1
Hi Anto,
You can try to split or remove the first two characters getting from database and then you can compare the field values.