When you run a cfquery using SELECT, the number of records returned is easy to find using #queryname.recordcount# - but what about the other types of SQL queries, our good friends Update, Insert and Delete ? Those query types don't return a total of rows in the same way.

But there's an easy solution ... once again, we can use 'recordcount', but in this case it is a node of the 'result' variable as defined in our cfquery tag.

view plain print about
1<cfquery datasource="#request.dsn#" name="saveChanges" result="updateResult">
2UPDATE table_name
3SET
4column1 = '#value1#',
5column2 = '#value2#'
6WHERE column3 = 1
7</cfquery>
8
9<cfset recordsChanged = updateResult.recordCount>

That query is just a sample, you could have any 'where' statement, values, etc... but notice the "result" attribute of the cfquery tag, which will accept any variable name you want to use. Then, immediately following the query code, we simply get the 'recordcount' node of the result structure, and we have the number of updated records from the query.

( Note: this example is for mySQL - ymmv with other db types)