I am creating a dynamic query.
string s = '%' + searchText + '%';
string query = 'Select name, ShippingCity, ShippingState, ShippingCountry, rating, type, Industry, ownerId From Account Where name LIKE : '+s+' OR BillingAddress LIKE : '+s+' OR website LIKE : '+s+' OR AccountNumber LIKE : '+s;
System.QueryException: line 1:122 no viable alternative at character '%'
Best Answer
You need to wrap it in single quotes, not precede it with a colon (
:
).Or if you want to use bind variables, you can just wrap your
searchText
variable: