dynamic Query

Reply

Join Date: Sep 2007
Posts: 15
Reputation: moiseszaragoza is an unknown quantity at this point 
Solved Threads: 0
moiseszaragoza moiseszaragoza is offline Offline
Newbie Poster

dynamic Query

 
0
  #1
Jun 7th, 2009
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>
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 3
Reputation: gdmprog1 is an unknown quantity at this point 
Solved Threads: 0
gdmprog1 gdmprog1 is offline Offline
Newbie Poster

Re: dynamic Query

 
0
  #2
Jun 11th, 2009
You have <cfoutput>#SQL#</cfoutput>
but in the cfquery you only have SQL, try enclosing the #SQL#
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for ColdFusion
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC