943,546 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Unsolved
  • Views: 1602
  • ColdFusion RSS
Jun 7th, 2009
0

dynamic Query

Expand Post »
I have a SQL Query build as a string but i cant seem to pass it into to the <cfquery>

But it does not work

any one can help me?

<cfif ISDEFINED ('member')>
<CFSET SQL = "SELECT *
FROM precontract ">  
<CFSET SQL_Coubr = 0 >
<cfif form.member neq  "">
	<cfif SQL_Coubr eq  0>
    	<CFSET SQL = SQL& " WHERE " >
    <cfelse>
    	<CFSET SQL = SQL& " OR " >  
    </cfif>      
	<CFSET SQL = SQL& " name LIKE '%#form.member#%' " >
    <CFSET SQL_Coubr = 1 >
</cfif>      

<cfif form.Email neq  "">
	<cfif SQL_Coubr eq  0>
    	<CFSET SQL = SQL& " WHERE " >
    <cfelse>
    	<CFSET SQL = SQL& " OR " >  
    </cfif>      
	<CFSET SQL = SQL& " email LIKE '%#form.Email#%' " >
    <CFSET SQL_Coubr = 1 >
</cfif>      

<cfif form.Phone neq  "">
	<cfif SQL_Coubr eq  0>
    	<CFSET SQL = SQL& " WHERE " >
    <cfelse>
    	<CFSET SQL = SQL& " OR " >  
    </cfif>      
	<CFSET SQL = SQL& " phone  LIKE '%#form.Phone#%' " >
    <CFSET SQL_Coubr = 1 >
</cfif>  

<cfif form.ContractNumber neq  "">
	<cfif SQL_Coubr eq  0>
    	<CFSET SQL = SQL& " WHERE " >
    <cfelse>
    	<CFSET SQL = SQL& " OR " >  
    </cfif>      
	<CFSET SQL = SQL& " conID LIKE '%#form.ContractNumber#%' " >
    <CFSET SQL_Coubr = 1 >
</cfif>  
<cfoutput>#SQL#</cfoutput>
<cfquery datasource="mssqlcf_modelprod" dbname="modelprod"  name="get_prememb">
        SQL    
</cfquery>
</cfif>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
moiseszaragoza is offline Offline
15 posts
since Sep 2007
Jun 11th, 2009
0

Re: dynamic Query

You have <cfoutput>#SQL#</cfoutput>
but in the cfquery you only have SQL, try enclosing the #SQL#
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gdmprog1 is offline Offline
3 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: cfajax broken in CF 8.0.1?
Next Thread in ColdFusion Forum Timeline: Need Help for Resume parsing using Poi and coldfusion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC