Dumping A Select/Insert Query

I have a query that does a select/insert:


INSERT
INTO myTable (...)
SELECT (...)
FROM theOtherTable
WHERE 1=1

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…

Recent Related Posts

2 thoughts on “Dumping A Select/Insert Query

  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. you can also try

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

    output command also works for updated, deleted

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>