2

Dumping A Select/Insert Query

Posted November 13th, 2009. Filed under Code

I have a query that does a select/insert:


<cfquery name="data">
INSERT
INTO myTable (...)
SELECT (...)
FROM theOtherTable
WHERE 1=1
</cfquery>

I was trying to figure out what was going on in this query but doing a simple cfdump of ‘data’ was throwing an error (btw this is on CF8).   Reading the docs I noticed there is a “results” attribute:

Specifies a name for the structure in which cfquery returns the result variables.

So I modified my query to add a result and then dumped that and it worked!

<cfquery name=”data” result=”testdata”>
<cfdump var=”#testdata#”>

Hopefully this is helpful to others…

Possibly Related:

  • No related posts found.
If you have enjoyed this entry. Please feel free to bookmark it using your favorite social bookmarking site

2 Responses so far

  1. @Jim
    One other thing that you may find very useful to know is that the result will also hold the primary key when you’re performing an INSERT statement. This is great if you need to have a cfc return the primary key and your table is using IDENTITY (SQL Server) or Auto-Increment (MySQL).

  2. richard says:

    you can also try

    INSERT INTO myTable (…)
    OUTPUT INSERTED.*
    SELECT (…)
    FROM theOtherTable
    WHERE 1=1

    output command also works for updated, deleted

Leave a Comment