sql server agent jobs schedule question

Hello experts. I have a sql script the runs a stored procedure. The stored procedure clears and updates some rows in some tables. So when I run the sql script in visual studio, it shows me the results of what rows were updated. Example:
0 rows affected
0 rows affected
84 rows affected

I want to run this job as a scheduled job and I think I have it setup correctly. Except here is my question. When the scheduled job kicks off all I get is an email that the job was successful but I do not see what rows were affected like I do in visual studio. Is it possible to see what rows were affected via a schedule job and if so how?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
It's better for the stored proc to handle that.

You can use the @@RowCount to get the last number of rows affected by the query.

so something like

declare @body varchar(max) = ''
-- insert query
select @body = @@RowCount + ' rows inserted <br />'

-- update query;
select @body = @body + @@RowCount + ' rows updated <br />'

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'theProfile',
    @recipients = 'your email',
    @body = @body,
    @subject = 'TheStoredProc Results' ;

Open in new window

more on sp_send_dbMail here:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott PletcherSenior DBACommented:
If that's something you need to know, I'd log it into a table then include a SELECT in the email to pull the relevant data for that email.  You could set up a process to automatically delete obsolete data from the table.
tmaususerAuthor Commented:
Thank you so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.