I bet, every programmer know "LIKE" searching type in all RDBMS. It's so simple and can help us to search by all types of character. Unfortunately, we need to avoid using LIKE command if we really don't need it because it can make query performance to getting slow and sometimes, RDBMS can be crush. Today, I need to use create simple UDF in Coldfusion for LIKE command. Because, we need consistency for LIKE command in our searching query.
That's why I wrote following UDF for LIKE.
2 <cfargument name="SearchParam" type="string" default="">
3 <!--- If search method doesn't declare, STARTING is default. --->
4 <cfargument name="SearchMethod" type="string" default="STARTING">
5 <cfset ReturnResult = "">
6 <cfswitch expression="#SearchMethod#">
7 <cfcase value="STARTING">
8 <cfset ReturnResult = SearchParam & "%">
9 </cfcase>
10 <cfcase value="ENDING">
11 <cfset ReturnResult = "%" & SearchParam>
12 </cfcase>
13 <cfcase value="WITHIN">
14 <cfset ReturnResult = "%" & SearchParam & "%">
15 </cfcase>
16 <cfcase value="EXACT">
17 <cfset ReturnResult = SearchParam>
18 </cfcase>
19 <cfdefaultcase>
20 <cfset ReturnResult = SearchParam & "%">
21 </cfdefaultcase>
22 </cfswitch>
23 <cfreturn ReturnResult>
24</cffunction>

Android
Top of Page