Good day, I write a simple trigger in MS SQL and gives an error in the WHERE block object_name = @name_device. he cannot compare a string without quotes.

CREATE TRIGGER tcontrolpuskdev ON [dbo].[tcontrol] AFTER INSERT AS DECLARE @pusk1 int(1), @name_device varchar(6); SET @pusk1 = (SELECT TOP(1) Puskatel1 from instered) SET @name_device = (SELECT TOP(1)Puscatel1 FROM INSERTED) UPDATE devices SET pusk1_dev = @pusk1 WHERE object_name = @name_device GO 

Here is the error text itself:

Msg 2716, Level 16, State 1, Procedure tcontrolpuskdev, Line 11 [Batch Start Line 0] Column, parameter, or variable # 1: Cannot specify an int.

Please advise how to solve this problem.

    1 answer 1

    In MS SQL Server, int cannot set the size. Replace int(1) with int .

    • Rather, on decimal(1) ? - Qwertiy
    • @Qwertiy is actually better to be replaced by the type specified in the Puskatel1 column in tcontrol (the main thing is not to be confused with Puscatel1) - PashaPash
    • @PashaPash I looked more attentively at this creation and instead of Puscatel1, I need to put object_name and instead of instered -> inserted. As a result, there are no syntax errors. But when launched, it gives an incorrect name in CREATE TRIGGER - Vladislav E.