Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
swims01
Yak Posting Veteran
59 Posts |
Posted - 2009-05-05 : 16:22:35
|
| Hey all. I'm searching through the site right now but a lot of the results are more complicated than what I'm trying to do.I've created my SQL query (Saved as myscript.sql)I've set up my mail profile within SQL Server 2005 and tested it with success.How can I set my query to run at a specific time every night and send the results through email?Thanks and I'll continue to search in the mean time.edit* I found the following from another site. It has the query within the code but I'd like to reference my file instead of putting my entire query in there...EXEC msdb.dbo.sp_send_dbmail@recipients=N'chapman.tim@gmail.com',@body='Message Body', @subject ='Message Subject',@profile_name ='DatabaseMailProfile',@query ='SELECT Product FROM sb2..SalesHistory GROUP BY Product HAVING COUNT(*) > 3', @attach_query_result_as_file = 1,@query_attachment_filename ='Results.txt' |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
swims01
Yak Posting Veteran
59 Posts |
Posted - 2009-05-05 : 17:37:59
|
| I'd actually prefer to send the results of the query in the body of the email. I just need to see if it's possible to reference the SQL script instead of inserting the actual code.Ex.EXEC msdb.dbo.sp_send_dbmail@recipients=N'user@domain.com',@body='Message Body', @subject ='Message Subject',@profile_name ='DatabaseMailProfile',@query = "C:\myscript.sql", @attach_query_result_as_file = 0It's the [ @query = "C:\myscript.sql" ] statement that I'm interested in. If it can reference a .SQL file then I'm in the clear. But if I have to manually insert my query into that then it's not the end of the world, but I'll have to remember to update in the SQL Job after I make edits to the actual file. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
swims01
Yak Posting Veteran
59 Posts |
Posted - 2009-05-05 : 17:50:46
|
| Ok, thanks. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|