I believe I'm seeing this both when running a T-SQL script directly in SQL Server Agent, or when executing SQL Tasks in an SSIS package.
I have a stored procedure that does a lot of inserts in to Table A and then subsequent SQL statements that act on those inserted rows in Table A.
The problem in both SQL Server Agent (when using a T-SQL step) or when running an SSIS package in SQL Server Agent** is that it sure seems that the task running the stored procedure, just to illustrate, inserts 5,000 rows and then control is passed to the next Execute SQL statement when really the stored procedure has not finished yet and will insert another 4,000 before it is done.
I know this because if I run the same T-SQL script in SSMS, the results are correct and as expected.
In any event, any thoughts appreciated. Thanks.
** the T-SQL step and the SSIS package do the same thing, the code in the SSIS package just uses Execute SQL Statements that were ripped out of the T-SQL step.