I have created a the following strings:
set l_project_name = concat("UPPER(a.project_name) like UPPER ('%",projectName,"%')");
set l_project_type = concat(" OR UPPER(a.project_type) like UPPER('%",projectType,"%')");
set l_project_description = concat(" OR UPPER(a.project_description) like UPPER('%",projectDescription,"%')");
set l_full_search_clause = concat(l_project_name ,l_project_type, l_project_description);
The result of the string: l_full_search_clause is :
UPPER(a.project_name) like UPPER(‘%order%’)
I have a select clause that i need to use this string that i have created that contains this where clause. So, i have the following :
select * from projects
where l_full_search_clause
But, of course, MYSQL reads l_full_search_clause as is and not as a variable. How can i tell MYSQL that the condition is a variable string ?
This sql is in a MYSQL stored procedure .. so its just plain sql .. I am calling this stored procedure from C#, MVC3
Try this:
I believe you have to use the
@varsyntax for variables. Also, to execute a query which is stored in a string, you have to usePREPAREandEXECUTE.And you don’t have to use
UPPERon strings. By default, MySQL compares strings case-insensitively. You can ensure that by looking at collation type for you fields.ci_ones stand for “case insensitive”.