You need to sign in to do that
Don't have an account?
augiewaz
LIKE Statement in SQL Not Working
Hi,
I am running the following sql statement in my Apex code. However, it is not working correctly.
The issue is that the SQL statement is not returning account records where the name of the account contains the term 'new'
However, if I was to just have a string (WHERE name LIKE '%new%'), it does retrieve account records where at least the word "new" appears in the account name.
String accName = 'New'
List<Account> acc = [SELECT id, name FROM Account WHERE name LIKE :accName]; // only returns accounts if the name matches 100%
List<Account> acc = [SELECT id, name FROM Account WHERE name LIKE '%new%']; // returns any accounts where the name contains the word 'new'
Any help on this is appreciated. From what I understand, how I have written the SQL statement is correct. Its just not doing what it is supposed to do.
Thanks
Warren
You can try this.
List<Account> acc = [SELECT id, name FROM Account WHERE name LIKE :accName+'%'];
Thanks
Srini