query and send an email after a job finishes.

after a SQL job is complete, what step can be added to the job to query a table and send the result by email? or is it better to do outside the job?  (SQL 2012)
LVL 5
25112Asked:
Who is Participating?

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

x
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.

Haris DulicIT ArchitectCommented:
Hi,

if your job is calling some procedure, you can add your check (or call to another procedure which will check table and then send the results.

I always use another procedure for testing and mailing and then you can reuse it.

To send the results you can use sp_send_mail, on this link you can find more info on sp_send_mail procedure.
0
Mandeep SinghDatabase AdministratorCommented:
Hi,

You can add steps to your job to do so.

Like:

Step1: do whatever your job want to do.
Step2: Now query the table you want and store the output and send it to our email.

Like:
-- Start T-SQL
    USE msdb
    EXEC sp_send_dbmail
      @profile_name = 'MailProfile1',
      @recipients = 'someone@microsoft.com',
      @subject = 'T-SQL Query Result',
      @body = 'The result from SELECT is appended below.',
      @execute_query_database = 'msdb',
      @query = 'your select query goes here'
-- End T-SQL --

Open in new window


Reference: http://hightechnology.in/sql-query-result-set-html-table/
0

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
Vitor MontalvãoMSSQL Senior EngineerCommented:
25112, do you still need help with this question?
0
25112Author Commented:
figured out the error.. thanks all.

thanks to Vitor also!
0
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.