我想知道是否有人可以帮助我将这两个存储的过程合二为一。
CREATE PROCEDURE [dbo].[spGetMsgID]
-- Add the parameters for the stored procedure here
@SendingF varchar(50),
@SendingA varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT Prefix, Counter
FROM
dbo.Part p
JOIN
dbo.MsgIDG g
ON
p.ID = g.PartID
WHERE
p.Facility = @SendingF
AND
p.Application = @SendingA
END
GO
CREATE PROCEDURE [dbo].[spUpdateMsgID]
-- Add the parameters for the stored procedure here
@SendingF varchar(50),
@SendingA varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
UPDATE dbo.MsgIDG
SET Counter = Counter + 1
FROM
dbo.Part p
JOIN
dbo.MsgIDG g
ON
p.ID = g.PartID
WHERE
p.Facility = @SendingF
AND
p.Application = @SendingA
END
GO
第一个存储过程返回前缀和计数器,而第二个递增计数器。我想要做的是检查第一个存储过程是否返回至少一个结果集,如果是,则返回前缀和计数器并执行第二个存储过程。
无论如何将这两者组合成一个可能比运行两个单独的存储过程更有效。我最初考虑使用 IF ... ELSE 来检查结果集,返回两列并更新。
提前致谢