0

SELECT3 つの個別のステートメントを実行し、結果を変数に格納する必要があるストアド プロシージャがあります。

私はこのようなことを試しました:

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)

しかし、それは私に言うエラーを与えます

「(」付近の構文が正しくありません。

下の 2 つの s を削除すると、このステートメントは機能しSELECTます。他のオプションはありますか?

編集: 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
4

1 に答える 1

1

UPDATEステートメントから括弧を削除します。それらは不要です。

更新ステートメントは次のようになります。

UPDATE Posts
SET Description = @description, [Content] = @content, Title = @title, 
    [Date Modified] =@dateModified, HeaderImageName = @headerImageName, 
    slug =@slug
WHERE id = @id
于 2012-11-14T19:20:00.710 に答える