February 26, 2010 at 8:28 am
Goal: Send an email when a specific stored procedure is run
1. Create dbmail send stored procedure
2. Call or execute the mail stored procedure from the other stored procedure
I can't even create the stored procedure. It's telling me the EXEC line is incorrect. Here is the code:
USE [CVEpi]
GO
/****** Object: StoredProcedure [dbo].[EmailEventSend] Script Date: 02/25/2010 13:23:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Version 0.1 common email procedure
CREATE PROCEDURE [dbo].[EmailEventSend]
--Send Email Notification
EXEC msdb.dbo.sp_send_dbmail
@profile_name='Basic',
@recipients='mike@somewhere.com',
@subject='You have a new event',
@body='A new engagement has been requested. Please check the website'
--EndEmail
Then, how do I call or execute this stored procedure from within another stored procedure.
Thanks so much for your help.
February 26, 2010 at 8:45 am
at a minimum, you are missing the AS keyword:
CREATE MyProc
AS--buncha code
CREATE PROCEDURE [dbo].[EmailEventSend]
--Send Email Notification
AS
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name='Basic',
@recipients='mike@somewhere.com',
@subject='You have a new event',
@body='A new engagement has been requested. Please check the website'
--EndEmail
--Do other stuff
END
Lowell
February 26, 2010 at 8:51 am
Lowell,
Thank you very much. It's always the little things that make the biggest problems. Your solution, of course, worked.
Mike
February 26, 2010 at 8:56 am
yeah, pre-caffeine coding messes me up almost every day; I know how the little things can getcha.
glad you got it now!
Lowell
February 26, 2010 at 9:00 am
Can you tell me how to call the stored proc EmailEventSend from within another stored proc? I need to send an email when that stored proc is run.
Thanks.
February 26, 2010 at 9:07 am
easy...you just have to explicitly use the EXEC or EXECUTE command:
CREATE PROCEDURE MyProc (@tblname sysname)
AS
BEGIN
SET NOCOUNT ON
--ack! someone used this proc! send an email
--current incarnation of EmailEventSend has no parameters
EXEC EmailEventSend
--do other stuff
SELECT * FROM sys.objects WHERE name = @tblname
END
Lowell
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply