[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 753
  • Last Modified:

The variable in a SQL query

Hi.

Im having a problem with a query.

I do a query like so:

<cfquery name="get_databases" datasource="databasename">
  SHOW DATABASES;
</cfquery>
<cfdump var="#get_databases#">

When I do the dump I can see the value for the database name is "DATABASE"
So when I do
<cfloop query="databases">
  <cfoutput>#DATABASE#</cfoutput>
</cfloop>
I get the names of the databases.

My problem is however this:
I want to see the SQL statement to create/copy a table so  I do this:
<cfquery name="show_create" datasource="databasename">
  SHOW CREATE TABLE sometable
</cfquery>      
<cfdump var="#show_create#">
When I do the dump I can see the value for the create table is "CREATE TABLE"
So when I do :
<cfloop query="show_create">
  <cfoutput>#CREATE TABLE#</cfoutput>
</cfloop>
I get an error because there is a space between "CREATE" and "TABLE".

Does anybody know of a different why to get the values of the "show_create" statement I did?

Best regards,  Burkni



0
Fern2
Asked:
Fern2
  • 2
1 Solution
 
hartCommented:
Try this and let me know

<cfquery name="show_create" datasource="databasename">
  SHOW CREATE TABLE sometable
</cfquery>

<cfoutput query="show_create">
  #show_create[currentrow]#
</cfoutput>

Regards
Hart
0
 
MauseCommented:
Hi

Hart you also need to add ["CREATE TABLE"] to the table in you output

<cfoutput query="show_create">
  #show_create["CREATE TABLE"][currentrow]#
</cfoutput>

Mause
0
 
hartCommented:
Mause : True i missed that out

Regards
Hart
0
 
Fern2Author Commented:
Thanks guys.

The Mause way worked
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now