我有一个存储过程,我需要运行三个单独SELECT
的语句并将结果存储在一个变量中。
我试过这样的事情:
SELECT @tier1MenuIds = Id
FROM TheGateKeeper.NavigationTier1
WHERE ([Page Name] = @currentSlug)
SELECT @tier2MenuIds = Id
FROM TheGateKeeper.NavigationTier2
WHERE ([Page Name] = @currentSlug)
SELECT @tier3MenuIds = Id
FROM TheGateKeeper.NavigationTier3
WHERE ([Page Name] = @currentSlug)
但它给了我一个错误说
'(' 附近的语法不正确。
如果我删除底部的两个SELECT
s,则该语句有效。还有其他选择吗?
编辑:我正在使用 SQL Server。这是完整的代码:
CREATE PROCEDURE [TheGateKeeper].[editContent]
@description nvarchar(300),
@content nvarchar(MAX),
@title nvarchar(50),
@dateModified date,
@headerImageName nvarchar(100),
@slug nvarchar(50),
@id int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @currentSlug as nvarchar(100);
DECLARE @tier1MenuIds as int;
DECLARE @tier2MenuIds as int;
DECLARE @tier3MenuIds as int;
/* Check if the post exists */
SELECT @currentSlug = Slug
FROM TheGateKeeper.Posts
WHERE (Id = @id)
IF (@@ROWCOUNT = 1)
BEGIN
/* Temporarily unlink all menu items linking to post */
SELECT @tier1MenuIds = Id
FROM TheGateKeeper.NavigationTier1
WHERE ([Page Name] = @currentSlug)
SELECT @tier2MenuIds = Id
FROM TheGateKeeper.NavigationTier2
WHERE ([Page Name] = @currentSlug)
SELECT @tier3MenuIds = Id
FROM TheGateKeeper.NavigationTier3
WHERE ([Page Name] = @currentSlug)
/* Update the post in the database */
UPDATE Posts
SET (Description = @description, [Content] = @content, Title = @title, [Date Modified] =@dateModified, HeaderImageName = @headerImageName, slug =@slug)
WHERE id = @id
RETURN 1
END
ELSE
BEGIN
RETURN 0
END