Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    139

    Unanswered: #of rows updated

    Is there a command that will tell me the number of rows that are updated in a statement. I would like to put this in an Stored Procedure and pass the #rows updated back out.
    Thanks,
    Bill

  2. #2
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716
    you can just look at @@ROWCOUNT after you do a statment and it will tell you how many rows were affected by the last SQL statement.

    i.e., SELECT @@ROWCOUNT

    or better yet, put it into a local variable such as:

    Code:
    DECLARE @RowCountToReturn int
    
    SELECT * FROM dbo.MyTable
    SET @RowCountToReturn = @@ROWCOUNT
    Keep in mind that pretty much EVERY SQL statement changes the value of @@ROWCOUNT, so you need to save it off if you have any code that may change it before you return it to your calling procedure.
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •