I've got problems with my triggers (add and delete):
ALTER TRIGGER [trgAfterShoppingInserted]
ON [ShopingList] AFTER INSERT
AS BEGIN
DECLARE @cardId char(6), @points int, @userId int
SET @cardId = (SELECT cardId FROM inserted)
SET @points = (SELECT points FROM inserted)
SET @userId = (SELECT userId from [Card] WHERE id = @cardId)
IF @userId = 0
BEGIN
Update [Card]
set points = points + @points
where id =@cardId
END
ELSE
Update [Card]
set points = points + @points
where id =@cardId OR
userId = @userId
END
ALTER TRIGGER [trgAfterShoppingDeleted]
ON [ShopingList] AFTER DELETE
AS BEGIN
DECLARE @cardId char(6), @points int, @userId int
SET @cardId = (SELECT cardId FROM inserted)
SET @points = (SELECT points FROM inserted)
SET @userId = (SELECT userId from [Card] WHERE id = @cardId)
IF @userId = 0
BEGIN
Update [Card]
set points = points - @points
where id =@cardId
END
ELSE
Update [Card]
set points = points - @points
where id =@cardId OR
userId = @userId
END
The problem is on the SET @cardId..
The error is:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
how is it possibile ?
thanks for any help