I have a Table Products with a Trigger to create a record on each update made to Products (something like a Log).
Everything works fine if I update one record at a time but if I try to update multiple records (Update Products SET Name = "BLABLABLA" WHERE Price > 10) I get the following error:
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <=, >, >= or when the subquery is used as an expression. The statement has been terminated."
My Trigger is this one:
CREATE TRIGGER [dbo].[NS_Art_Export_ProdUpdate] ON [dbo].[Produtos] FOR UPDATE
AS BEGIN
DECLARE @Key1 NVARCHAR(20), @Key2 NVARCHAR(20)
DECLARE @Changed BIT
SET @Key1 = (SELECT Counter FROM INSERTED)
SET @Key2 = (SELECT Prod_Gen FROM INSERTED)
SET @Changed = 0
IF UPDATE(Codigo) SET @Changed = 1
IF UPDATE(NOME) SET @Changed = 1
IF UPDATE(Familia) SET @Changed = 1
IF UPDATE(CodIVA) SET @Changed = 1
IF UPDATE(qtEmbal) SET @Changed = 1
IF UPDATE(Volume) SET @Changed = 1
IF UPDATE(PesoBrt) SET @Changed = 1
IF UPDATE(PesoLiq) SET @Changed = 1
IF UPDATE(Status) SET @Changed = 1
IF @Changed = 1
INSERT INTO Log_NSArtSoft
(Tabela, Tipo, Key1, Key2, Data_Update,
Data_Export, Flag_Update, Data_Export2)
VALUES
('Produtos', 'U', @Key1, @Key2, GETDATE(),
0, 0, 0)
END
GO
Can someone help me with this? Thanks
[dbo].in your code. Please correct if that's not the case.INSERTEDtable and you can't assign it to variable. You should follow this answer by @mehdi lotfi stackoverflow.com/questions/12137102/…