jcorbin
asked on
ColdFusion Query
Is there a way that I can assign the query I just ran in a <CFQUERY> tag to a variable so I can store the actual SQL text? Does the Query Object have a property that contains the query?
No, the Query Object does not store the sql. Of couse tyou could do it like dlewis9 has said but that is not what you asked is it. So the answer to your question is NO the query object does not have a object that contains the sql text in it.
I agree with nathans. Query object does not store the sql value.
I assume that u want to store the sql value somewhere for future use.
U can construct the query using the variable and execute it like what dlewis9 said.
<CFSET sqltext = "SELECT * FROM TABLE">
<CFQUERY NAME="qry" DATASOURCE="datasource">
#sqltext#
</CFQUERY>
Then u can store the value in the form. That query(sql) can be executed in the consecutive pages. It can also be used while reloading the page.
I believe that this is what u asked. Good luck
I assume that u want to store the sql value somewhere for future use.
U can construct the query using the variable and execute it like what dlewis9 said.
<CFSET sqltext = "SELECT * FROM TABLE">
<CFQUERY NAME="qry" DATASOURCE="datasource">
#sqltext#
</CFQUERY>
Then u can store the value in the form. That query(sql) can be executed in the consecutive pages. It can also be used while reloading the page.
I believe that this is what u asked. Good luck
If I'm reading your question right, you want to create a page with a CFQuery and then output both the query's results and the actual query. As mentioned by both smuniasamy and dlewis9 you can use the CFSet tag to define the actual query. Check the exact length of the cfset tag though, since it may limit string lengths to 254 characters or something silly like that. I haven't tested this, but if I'm reading your question right, this should work:
<cfset #sql1# = "Select * From Table">
<cfset #sql2# = "Where <criteria>">
<cfset #sql3# = "Order By <whatever>">
<cfquery name="Testit" datasource="source" dbtype="ODBC">
#Sql1#
#Sql2#
#Sql3#
</cfquery>
<html>
<head>
</head>
<body>
<cfoutput>
Results for Query:<br>
#Sql1#<br>
#Sql2#<br>
#Sql3#<br>
</cfoutput>
<cfoutput query="Testit">
....(Insert your output here)
</cfoutput>
</body>
</html>
That looks like it will work, but that's only if I'm reading what you're wanting to have done right.
Hatton Humphrey
<cfset #sql1# = "Select * From Table">
<cfset #sql2# = "Where <criteria>">
<cfset #sql3# = "Order By <whatever>">
<cfquery name="Testit" datasource="source" dbtype="ODBC">
#Sql1#
#Sql2#
#Sql3#
</cfquery>
<html>
<head>
</head>
<body>
<cfoutput>
Results for Query:<br>
#Sql1#<br>
#Sql2#<br>
#Sql3#<br>
</cfoutput>
<cfoutput query="Testit">
....(Insert your output here)
</cfoutput>
</body>
</html>
That looks like it will work, but that's only if I'm reading what you're wanting to have done right.
Hatton Humphrey
Please Grade this one
You have several answers
Grade this for someone.
You have several answers
Grade this for someone.
ASKER
None of the answers do what I need
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Comment accepted as answer
<CFSET sqltext = "SELECT * FROM TABLE">
<CFQUERY NAME="qry" DATASOURCE="datasource">
#sqltext#
</CFQUERY>
Then, you can use sqltext after the query has been run..