多部分标识符" x"无法受约束

时间:2016-07-06 21:38:31

标签: sql-server tsql

我收到错误The multi-part identifier "inserted.PlaceId" could not be bound. 有什么问题?

CREATE TRIGGER UpdateVotes
    ON [dbo].[VoteLog]
    FOR INSERT, UPDATE
    AS
    BEGIN
    DECLARE @CurrentVotesNo int
    SET NOCOUNT ON
    SET @CurrentVotesNo = (SELECT Votes from dbo.[Places] where Id = inserted.PlaceId)

    if ( select Vote from inserted ) = 1
        BEGIN
            UPDATE dbo.[Places]
            SET Votes = @CurrentVotesNo, @CurrentVotesNo=@CurrentVotesNo+1
            from [dbo].[Places]
            join inserted
            on [dbo].[Places].Id = inserted.PlaceId
        END
    else if ( select Vote from inserted ) = -1
        BEGIN
            update dbo.[Places]
            SET Votes = @CurrentVotesNo, @CurrentVotesNo=@CurrentVotesNo-1
            from [dbo].[Places]
            join inserted
            on [dbo].[Places].Id = inserted.PlaceId
        END
    END

我也试过加入,像这样:SET @CurrentVotesNo = (SELECT Votes from dbo.[Places] p join dbo.VoteLog on p.Id = inserted.PlaceId )

0 个答案:

没有答案