Note that there are some explanatory texts on larger screens.

plurals
  1. POStored Procedure Does Not Fire Last Command
    primarykey
    data
    text
    <p>On our SQL Server (Version 10.0.1600), I have a stored procedure that I wrote.</p> <p>It is not throwing any errors, and it is returning the <strong>correct values</strong> after making the insert in the database.</p> <p>However, the last command <code>spSendEventNotificationEmail</code> (which sends out email notifications) is not being run.</p> <p>I can run the <code>spSendEventNotificationEmail</code> script manually using the same data, and the notifications show up, so I know it works.</p> <p>Is there something wrong with how I call it in my stored procedure?</p> <pre><code>[dbo].[spUpdateRequest](@packetID int, @statusID int output, @empID int, @mtf nVarChar(50)) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @id int SET @id=-1 -- Insert statements for procedure here SELECT A.ID, PacketID, StatusID INTO #act FROM Action A JOIN Request R ON (R.ID=A.RequestID) WHERE (PacketID=@packetID) AND (StatusID=@statusID) IF ((SELECT COUNT(ID) FROM #act)=0) BEGIN -- this statusID has not been entered. Continue SELECT ID, MTF INTO #req FROM Request WHERE PacketID=@packetID WHILE (0 &lt; (SELECT COUNT(ID) FROM #req)) BEGIN SELECT TOP 1 @id=ID FROM #req INSERT INTO Action (RequestID, StatusID, EmpID, DateStamp) VALUES (@id, @statusID, @empID, GETDATE()) IF ((@mtf IS NOT NULL) AND (0 &lt; LEN(RTRIM(@mtf)))) BEGIN UPDATE Request SET MTF=@mtf WHERE ID=@id END DELETE #req WHERE ID=@id END DROP TABLE #req SELECT @id=@@IDENTITY, @statusID=StatusID FROM Action SELECT TOP 1 @statusID=ID FROM Status WHERE (@statusID&lt;ID) AND (-1 &lt; Sequence) EXEC spSendEventNotificationEmail @packetID, @statusID, 'http:\\cpweb:8100\NextStep.aspx' END ELSE BEGIN SET @statusID = -1 END DROP TABLE #act END </code></pre> <p>Idea of how the data tables are connected:</p> <p><img src="https://i.stack.imgur.com/kmZfA.png" alt="my database"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload