0
我有一个存储过程,我需要运行三个单独的SELECT
语句并将结果存储在变量中。如何在存储过程中存储多个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] [email protected], HeaderImageName = @headerImageName, slug [email protected])
WHERE id = @id
RETURN 1
END
ELSE
BEGIN
RETURN 0
END
您正在使用哪个数据库管理系统? –
你可以发布你的sp?的整个代码,因为它是,没有错误 – Lamak
你缺少'END' – Lamak