Content

ramblings of a coldfusion developer

Dumping A Select/Insert Query

Friday 13 November 2009 - Filed under Code

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…

2009-11-13  »  Jim Priest

Talkback x 2

  1. Andy Sandefer
    13 November 2009 @ 6:20 pm

    @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
    14 November 2009 @ 2:54 am

    you can also try

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

    output command also works for updated, deleted

Share your thoughts

Re: Dumping A Select/Insert Query







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>