Я хочу обновить таблицу «MakinelerVeParcalar» с помощью этого запроса;
UPDATE MakinelerVeParcalar SET Durum = 'Montaj' WHERE ID = 161
И я получил эту ошибку;
Сообщение 512, Уровень 16, Состояние 1, Процедура trgSureUpdate,Строка 31 [Batch Start Line 0] Подзапрос возвратил более 1 значения.Это недопустимо, если подзапрос следует =,! =, <, <=,>,> = Или когда подзапрос используется в качестве выражения.
Мой trgSureUpdate (Trigger)
ALTER TRIGGER [dbo].[trgSureUpdate]
ON [dbo].[MakinelerVeParcalar]
AFTER UPDATE
AS
BEGIN
DECLARE @count INT
DECLARE @idinserted INT
DECLARE @duruminserted VARCHAR(50)
DECLARE @max INT
DECLARE @iddeleted INT
DECLARE @durumdeleted VARCHAR(50)
DECLARE @datediff INT
DECLARE @durumbilgisi varchar(50)
DECLARE @sureinserted INT
DECLARE @suredeleted INT
DECLARE @diffdate INT
SELECT @idinserted = ID from inserted <-- Line 31
SELECT @duruminserted = Durum from inserted
SELECT @iddeleted = ID from deleted
SELECT @durumdeleted = Durum from deleted
SET @count = (SELECT count(*) FROM Sure WHERE ID = @idinserted and Asama = @duruminserted)
SET @max = (SELECT max(SiraNo) FROM Sure WHERE ID = @idinserted)
SET @durumbilgisi = (SELECT DurumBilgisi FROM DurumBilgisi WHERE ID = @idinserted)
SET @sureinserted = (SELECT Sure FROM Sure WHERE ID = @idinserted and Asama = @duruminserted)
SET @suredeleted = (SELECT Sure FROM Sure WHERE ID = @iddeleted and Asama = @durumdeleted)
IF @duruminserted != @durumdeleted
BEGIN
IF @durumbilgisi != 'Bitti'
BEGIN
UPDATE Sure Set Cikis = GETDATE() WHERE Asama = @durumdeleted and ID = @idinserted and SiraNo = @max
SET @diffdate = DATEDIFF (SECOND,(SELECT Giris FROM Sure WHERE ID = @idinserted and SiraNo = @max),(SELECT Cikis FROM Sure WHERE ID = @idinserted and SiraNo = @max))
UPDATE Sure SET Sure = (@diffdate) WHERE ID = @idinserted and SiraNo = @max
END
INSERT INTO Sure (ID,Asama,Giris,Cikis,Sure,SiraNo) VALUES(@idinserted,@duruminserted,GETDATE(),NULL,0,(@max+1))
UPDATE DurumBilgisi SET DurumBilgisi = 'Devam Ediyor' WHERE ID = @idinserted
END
END