Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem Select Query with "Like"

2 views
Skip to first unread message

IRC

unread,
Apr 6, 2009, 5:24:20 AM4/6/09
to
hey guys, i haven't work much in coldfusion, i am try to search the
data using WHERE CLAUSE LIKE, I have wrote a function as following
which give Syntax error, i don't know what wrong with the following
function, please correct me.....

<cffunction name="searchActiveDirectoryList" access="public"
returnType="query" output="false">
<cfargument name="bean" type="directoryBean" required="true">
<cfset var q = "" />
<cfset var beanCommunity = "#arguments.bean.getCommunity()#" />
<cfset var beanName = "#arguments.bean.getName()#" />
<cfset var beanServiceType = "#arguments.bean.getSPOffered()#" />
<cfset var searchClause = "" >

<cfif beanCommunity neq "">
<cfset beanCommunity = "`tdir_community` like '%#beanCommunity#%'">
</cfif>

<cfif beanName neq "">
<cfset beanName = "`tdir_name` like '%#beanName#'">
</cfif>

<cfif beanServiceType neq "">
<cfset beanServiceType = "`tdir_sp_offered` like
'%#beanServiceType#'">
</cfif>

<cfif (beanCommunity neq "") && (beanName neq "")>

<cfset searchClause = "(" & beanCommunity & " OR " & beanName & " )
AND " />

<cfelseif beanCommunity neq "">

<cfset searchClause = beanCommunity & " AND " />

<cfelseif beanName neq "">

<cfset searchClause = beanName & " AND " />

<cfelse>

<cfset searchClause = "" />

</cfif>

<cfif (searchClause neq "") && (beanServiceType neq "")>
<cfset searchClause = searchClause & beanServiceType & " AND " />

<cfelseif (searchClause eq "") && (beanServiceType neq "")>
<cfset searchClause = beanServiceType & " AND " />
<cfelse>
<cfset searchClause = searchClause />
</cfif>

<cfquery name="q" datasource="#variables.dsn#">
select `tdir_id` as DirID, `tdir_name` as Name,`tdir_community` as
Community,`tdir_area_served` as AreaServed,`tdir_ci_address` as
Address,`tdir_ci_phone` as Phone, `tdir_ci_fax` as Fax,
`tdir_ci_email` as Email,`tdir_sp_offered` as
SPOffered,`tdir_desc_eligibility` as
Eligibility,`tdir_desc_accessibility` as
Accessibility,`tdir_desc_link`, `tdir_timestamp` as TimeStamp,
`tdir_status` as Status,`ta_id` as UserID
from `#variables.table#`
where #searchClause# AND `tdir_status`='active'
order by `tdir_timestamp` DESC, `tdir_name` ASC
</cfquery>

<cfreturn q />
</cffunction>


!! thanks

0 new messages