/*In this example I am calling a stored procedure myProc and passing the argument as ntMLSID then it returns all the field details . In the next query I am filtering the result by matching the string to a returned field "vcFieldName"*/
<cfstoredproc datasource="#application.dsn#" procedure="myProc">
<cfprocresult name="fieldDetails" />
<cfprocparam type="in" cfsqltype="CF_SQL_INTEGER" value="#variables.ntMLSID#" />
<cfprocresult name="fieldDetails" />
<cfprocparam type="in" cfsqltype="CF_SQL_INTEGER" value="#variables.ntMLSID#" />
</cfstoredproc>
<cfquery dbtype="query" name="filterResult">
SELECT *
FROM
fieldDetails
WHERE
vcFieldName LIKE '%#variables.vcSearchedField#%'
</cfquery>SELECT *
FROM
fieldDetails
WHERE
vcFieldName LIKE '%#variables.vcSearchedField#%'
Here in the above query everything is seems good. But the issue is that the above set of code only can able to match(comparison) a case sensitive string .
e.g- If vcFieldName in the Query is "India" and we pass the search string as "ind" then it will not return any value. By default the string matching by the LIKE operator of QoQ is case sensitive.
So, how we will make it as case insensitive ???
We can do that by following ways:
<cfquery dbtype="query" name="filterResult">
SELECT *
FROM
fieldDetails
WHERE
LOWER(vcFieldName) LIKE '%#LCASE(variables.vcSearchedField)#%'
</cfquery>SELECT *
FROM
fieldDetails
WHERE
LOWER(vcFieldName) LIKE '%#LCASE(variables.vcSearchedField)#%'
In first case we use LOWER and LCASE functions . Similarly we can also use UPPER and UCASE to do the same as follow:
<cfquery dbtype="query" name="filterResult">
SELECT *
FROM
fieldDetails
WHERE
UPPER(vcFieldName) LIKE '%#UCASE(variables.vcSearchedField)#%'
</cfquery>SELECT *
FROM
fieldDetails
WHERE
UPPER(vcFieldName) LIKE '%#UCASE(variables.vcSearchedField)#%'
No comments:
Post a Comment