Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 help with msdb.dbo.sp_send_dbmail
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

joe8079
Posting Yak Master

USA
127 Posts

Posted - 10/30/2013 :  09:20:07  Show Profile  Reply with Quote
Hi, is it possible to embed a result set from a table into the msdb.dbo.sp_send_dbmail stored procedure when an email is sent out:

Below i'm creating a test temp table of 10 rows that I need to embed in the msdb.dbo.sp_send_dbmail. I need to embed the whole table which is about ten rows into that stored procuedure

Sample Data: Creates a test table of 10 rows


USE tempdb

CREATE TABLE #ValueTable ( [value] INT )


INSERT INTO #ValueTable
VALUES ( 1 ),
( 2 )
INSERT INTO #ValueTable
VALUES ( 3 ),
( 4 )
INSERT INTO #ValueTable
VALUES ( 5 ),
( 6 )
INSERT INTO #ValueTable
VALUES ( 7 ),
( 8 )
INSERT INTO #ValueTable
VALUES ( 9 ),
( 10 )



--Need to excecute this stored procedure and embed the temp table created above. Is this possible and if so how would I go about doing that?


EXEC msdb.dbo.sp_send_dbmail @profile_name = 'profileName',
@from_address = 'fromAddress', @recipients = 'Joe', @subject = 'data',
@sensitivity = 'Personal', @importance = 'High', @body_format = 'HTML',
@body = 'need to insert table of values from temp table #valueTable'


DROP TABLE #ValueTable





joe8079
Posting Yak Master

USA
127 Posts

Posted - 10/30/2013 :  09:59:18  Show Profile  Reply with Quote
I actually figured this out using this link:
http://www.mssqltips.com/sqlservertip/2347/send-email-in-a-tabular-format-using-sql-server-database-mail/
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000