How many rows were inserted?

  • Hi,

    Probably simple, but I can't find it..... after I inserted a number of rows into a table, where can I find how many rows that was?

    For example:

    INSERT INTO mytable

    SELECT name FROM persons WHERE lastname='Jones'

    SELECT @@number_of_inserted_rows

    Thanks!

  • are you not getting it in result pane?

    ----------
    Ashish

  • Either use @@ROWCOUNT as the immediately following comand after your insert statement or if you'd like to get more details from the values inserted use the OUTPUT clause in your INSERT statement. See BOL for details.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • If you do SET ROWCOUNT ON before you run it (which is the default..so as long as you don't set it to Off), it should display the number of rows affected (on the messages tab).

    Or if this is in a SP, then select @@rowcount directly after the insert will work, as said above (it has to be the next command).

  • ok, thanks!!!

    Ray

  • r.vanlaake-1086273 (8/21/2010)


    ok, thanks!!!

    Ray

    You say that but which suggestion did you follow? Some of these suggestions use a deprecated command and some won't give you what you want via code, just by eyeball. Which suggestion did you use?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I reply "OK Thanks" for all the people that give a suggestion. Tomorrow at the office I will try the various suggestions... so don'y know that now yet.

    Ray

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply