Bulk Inserting Data

One of the operations that we do often is insert multiple rows into a database.  Your inclination is probably to just loop over a cfquery and do the inserts.  While this will work it creates some excess overhead.   Your code may look something like this: <cfloop array=”#users#” index=”u”> <cfquery name=”insertData”> insert into mytable (firstname, lastname, email) values ( <cfqueryparam cfsqltype=”cf_sql_varchar” value=”#u.firstname#”>, <cfqueryparam cfsqltype=”cf_sql_varchar” value=”#u.lastname#”>, <cfqueryparam cfsqltype=”cf_sql_varchar” value=”#u.email#”> ) </cfquery></cfloop> While this fundamentally works it can cause performance issues.  Depending on configuration, […]

Unioning queries using query of query

Here is how you can union together two queries using query of query. This function would take two queries and use query of query to combine them into a single query. The code below assumes the columns from the two source queries are identical. You would need to modify if that isn’t the case. private any function combineQuery(qA, qB) { var qry1Result = arguments.qA; var qry2Result = arguments.qB; var qoqResult = ”; // create new query object var qoq = […]