Link to home
Start Free TrialLog in
Avatar of dunkin1969
dunkin1969

asked on

*** How to Schedule, Execute, and Export a SQL statement in SQL Server 2005

Hello Experts,
I have to run a query every morning and email the results to a few people.  Is there a way to automate this?  I am using SQL Server Management Studio in SQL Serve 2005.

The steps are:
1- Open query
2 - execute query
3 - export results to a file (or copy/paste results to email body)
4 - email recipients

Thanks!!
Avatar of rajvja
rajvja
Flag of United Kingdom of Great Britain and Northern Ireland image

You can create sql agent job and set notifications to send email.
schedule the job.
Steps:
1. Right click on Sql Agent and create new job
2. Create step.
3. Paste the query in the corresponding textbox.
4. Select schedule the job and set the schedule settings
5. Click notifications and set the options. Email -> if job fails bla bla
Avatar of dunkin1969
dunkin1969

ASKER

Thank you rajvja.  I am trying this now.
It looks like my option to email the results is grayed out.. so I am checking to see why.
ASKER CERTIFIED SOLUTION
Avatar of SQLTriVegg
SQLTriVegg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SQLTriVegg,
Yes, it looks like even though SQL Server Agent can execute a SQL command,  it doesn't provide a vehicle for emailing the actual results to a recipient.  Liek you said, the "notifications" are referring to the job outcome... whether it was a success or failure.

Thanks for the tip.