Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query as a variable

Status
Not open for further replies.

Lotruth

Programmer
Joined
May 2, 2001
Messages
133
Location
US
Is there a way to consolidate a query into a variable? I have to use a query several times on different pages and I need to know if there is a way to use the query as a variable instead?

Something like
<cfset query=<cfquery datasource=&quot;A&quot; name=&quot;A&quot;>
Select * From Table Where This=#that#
</cfquery>

Thanks
 
<cfquery datasource=&quot;worldwebspiders&quot; name=&quot;queryName&quot;>
Select file
From storage
</cfquery>

<cfset varName = queryName>

<cfoutput>
#varName.file#
</cfoutput> Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
Sylvano, thanks for your reply...

But I need a variable that contains the actual query structure (<cfquery>...</cfquery>), not just the query name.
 
then use this to output your query:

<cfoutput query=&quot;varName&quot; >
#file#
</cfoutput> Sylvano
dsylvano@hotmail.com

&quot;every and each day when I learn something new is a small victory...&quot;
 
Seems to me that you want to be able to display the query text by reference to a variable. You should be able to use:

<cfset myquery=&quot;<cfquery datasource=&quot;&quot;A&quot;&quot; name=&quot;&quot;A&quot;&quot;>
Select * From Table Where This=##that##</cfquery>&quot;>




John Hoarty
jhoarty@quickestore.com
 
I need to set a variable equal to the query text, but then I need to reference that variable later in the code and have it execute the query instead of just displaying it.
 


Why don't you put your query on an include page(qry_include.cfm) and cfinclude it where you need to use it?

<!--- qry_include.cfm --->
<cfquery datasource=&quot;A&quot; name=&quot;A&quot;>
Select * From Table Where This=#that#
</cfquery>


<!--- page that needs a query.cfm--->

<cfif IsDefined(&quot;that&quot;)>
<cfinclude template=qry_include.cfm>
</cfif>


Hope that helps.
 
That did it for me. Thanks a lot everybody for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top