Skip to main content
Inspiring
September 13, 2008
Question

Count Records Updated

  • September 13, 2008
  • 3 replies
  • 2536 views
I just simply need to count the number of records updated in a SQL statement, such a...
This topic has been closed for replies.

3 replies

Inspiring
September 13, 2008
> I was hoping there was a way around that. Are you sure there is no way to have the update query return a count of some sort to a variable?

Have you read the documentation for whatever database you're running? This
is a DB question, not a CF question: CF just passes SQL statments to the DB
driver, and - when appropriate - receives recordsets back from the DB
driver. It has no idea what goes on between those two events.

NB: when asking a DB question... it's always good to start by saying which
DB you're using, as the answer is going to be different for any given DB
system.

--
Adam
romeogqAuthor
Inspiring
September 16, 2008
Thanks for the reply, but I already understand that. The database is MS-SQL, my fault for not stating... although most probably already understood that by looking at the statement. In addition, there are a lot of intelligent individuals of differing backgrounds on this forum, so I am sure the odds are someone will have an applicable answer.

PS: This is by far not my first post, and I have been a member of this forum since 2002/3.
Inspiring
September 16, 2008
there is @@ROWCOUNT. refer to this link:
http://msdn.microsoft.com/en-us/library/ms187316.aspx

by the way, have you tried using query_name.RecordCount?

or maybe the result_parameter_name.RecordCount?

e.g.

<cfquery name="qryUpdateCell" datasource="blah" result="resultqryUpdateCell">
UPDATE myTable
SET myCell = thisData
WHERE myRecords = thisCriteria
</cfquery>
<cfoutput>#resultqryUpdateCell.RecordCount#</cfoutput>
romeogqAuthor
Inspiring
September 13, 2008
Thanks Dan for the quick response.

I was hoping there was a way around that. Are you sure there is no way to have the update query return a count of some sort to a variable?
Inspiring
September 13, 2008
run a select query before you do the update.