?
Solved

ColdFusion Query

Posted on 2000-03-21
8
Medium Priority
?
145 Views
Last Modified: 2013-12-24
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?
0
Comment
Question by:jcorbin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 2

Expert Comment

by:dlewis9
ID: 2641740
You can store it in a variable first, and then reference it later like this:

<CFSET sqltext = "SELECT * FROM TABLE">

<CFQUERY NAME="qry" DATASOURCE="datasource">
#sqltext#
</CFQUERY>

Then, you can use sqltext after the query has been run..
0
 
LVL 5

Expert Comment

by:nathans
ID: 2643382
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.
0
 

Expert Comment

by:smuniasamy
ID: 2644922
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
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 2

Expert Comment

by:kc5sig
ID: 2675909
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
0
 
LVL 5

Expert Comment

by:nathans
ID: 2907382
Please Grade this one

You have several answers

Grade this for someone.
0
 

Author Comment

by:jcorbin
ID: 2908454
None of the answers do what I need
0
 
LVL 2

Accepted Solution

by:
kc5sig earned 300 total points
ID: 2908555
Unfortunately I do not think that there is a way to report what specific SQL statements are used in a query without first setting them to a variable name or names as I mentioned in my previous comment.

Hatton
0
 

Author Comment

by:jcorbin
ID: 2909017
Comment accepted as answer
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question