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
cfqueryreturns 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
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).
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