在我们的 SQL Server(版本 10.0.1600)上,我编写了一个存储过程。
它没有抛出任何错误,并且在数据库中插入后返回正确的值。
但是,最后一个命令spSendEventNotificationEmail
(发送电子邮件通知)没有运行。
我可以spSendEventNotificationEmail
使用相同的数据手动运行脚本,并显示通知,所以我知道它有效。
我在存储过程中的调用方式有问题吗?
[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 < (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 < 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<ID) AND (-1 < Sequence)
EXEC spSendEventNotificationEmail @packetID, @statusID, 'http:\\cpweb:8100\NextStep.aspx'
END ELSE BEGIN
SET @statusID = -1
END
DROP TABLE #act
END
数据表如何连接的想法: