Kevin Smith
asked on
How to include table data in a stored procedure email body...?
I have the below procedure (well, you see it as the alter but same thing)...what I need to do is for the procedure to scan the table and grab the name and job number and expiry date of any record that has an expiry approach within 15 days. Then I need to be able to list that information out in the body of the email like this:
The following jobs have expiring dates:
Name: Billy Bob
Job Number: 15487
Expiring: 8/15/2013
Name: James Joyce
Job Number: 65148
Expiring: 8/22/2013
Here's what the basic procedure format...
ALTER PROCEDURE [dbo].[p_send_altermail]
AS
-- SELECT STATEMENT HERE TO PULL NAME, JOB NUMBER, EXPIRY DATE IF WITHIN 15 DAYS
BEGIN
EXEC msdb..sp_send_dbmail @profile_name='mssjobbook' ,
@recipients='mail@place.co m',
@subject='MSS Job Book Notification',
@body= ' The following jobs have a date expiring soon... ' ;
END
Thanks! (sql server 2005, using database mail)
The following jobs have expiring dates:
Name: Billy Bob
Job Number: 15487
Expiring: 8/15/2013
Name: James Joyce
Job Number: 65148
Expiring: 8/22/2013
Here's what the basic procedure format...
ALTER PROCEDURE [dbo].[p_send_altermail]
AS
-- SELECT STATEMENT HERE TO PULL NAME, JOB NUMBER, EXPIRY DATE IF WITHIN 15 DAYS
BEGIN
EXEC msdb..sp_send_dbmail @profile_name='mssjobbook'
@recipients='mail@place.co
@subject='MSS Job Book Notification',
@body= ' The following jobs have a date expiring soon... ' ;
END
Thanks! (sql server 2005, using database mail)
ASKER
Okay...so where is the actual select statement? I guess I'm looking something that's showing a select/from/where statement...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry, got on another project...gonna play with this again tomorrow...
(Only partial code here but you'll get the picture)
Open in new window