我收到错误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 )