Record Count In Execute SQL Task

Posted on 2009-12-17
Last Modified: 2013-11-10
I am trying to log counts of records inserted via a sql task. Can anyone tell me how best to do this. Right now I log counts in the data flow by using VB code in a Scrip Component, but I need to be able to capture counts in the SQL Task.
Question by:earngreen
    LVL 26

    Accepted Solution

    you may use the @@ROWCOUNT

    your insert statement goes here

    insert into ......

    following the insert statement the @@ROWCOUNT returns the number of rows affected in that ddl operation.  by using that you may issue a command like

    INSERT INTO yourLogTable
    SELECT @@ROWCOUNT, GETDATE()... etc...


    LVL 13

    Expert Comment

    A word of caution.
    @@ROWCOUNT would be reset for every instance of insert. So, you might have to save it for logging before/after commit.

    Author Comment


    I am not sure what you mean.
    LVL 26

    Expert Comment

    @@ROWCOUNT value changes after every ddl statement. for that reason you should use it immediatly after you run your query or store that value for later use.. this what sameer2010 mean.
    LVL 22

    Expert Comment

    Create a stored procedure with an output parameter using the @@RowCount function and get it from a SQLtask inside SSIS.
    FOr SQL task details check this link:

    Author Closing Comment

    This worked great. Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now