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.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Store Procedure Email

Author  Topic 

dtrivedi
Posting Yak Master

153 Posts

Posted - 2010-07-15 : 15:56:49
I need to write a store procedure where in the body of the email the body is coming from a table in the database

any help would be appreciated

thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-15 : 16:06:42
If you are using SQL Server 2005 or 2008, then you can use Database Mail. For SQL Server 2000, you'd use SQL Mail. Both allow you to run a query and put into the email. Check BOL for details or let us know if you have any questions.

There are other email options, but Database Mail and SQL Mail are built into SQL Server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dtrivedi
Posting Yak Master

153 Posts

Posted - 2010-07-15 : 16:08:36
We are running sql 2008
i know that an email can be sent but can the body of it be coming from a table in the database?
if so please send a script



quote:
Originally posted by tkizer

If you are using SQL Server 2005 or 2008, then you can use Database Mail. For SQL Server 2000, you'd use SQL Mail. Both allow you to run a query and put into the email. Check BOL for details or let us know if you have any questions.

There are other email options, but Database Mail and SQL Mail are built into SQL Server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-15 : 16:14:59
Here's an example using Database Mail:

EXEC msdb.dbo.sp_send_dbmail
@recipients = 'xxx@yyy.com',
@query = 'SELECT * FROM Database1.dbo.Table1' ,
@subject = 'Test'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dtrivedi
Posting Yak Master

153 Posts

Posted - 2010-07-16 : 10:42:17
hmm ok so that worked thanks for that
but now i need to add an html code in the body so it formats it better and also concat the fields....sorry am new at this!
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-07-16 : 11:05:19
Read the DOCs ... the various options are all described there
Go to Top of Page

dtrivedi
Posting Yak Master

153 Posts

Posted - 2010-07-16 : 11:10:14
THE DOCS?


quote:
Originally posted by Kristen

Read the DOCs ... the various options are all described there

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-16 : 11:22:49
See sp_send_dbmail in SQL Server Books Online for how to do the HTML. There's even an example in there.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -