Forum Discussion
Error when trying to create a Trigger
- Apr 14, 2025
Hi
I managed to resolve the issue. I think it was because the code I was using was mySQL and when I converted it to TSQL it works.
Thanks for trying to help.
Aaron
Hello ,
This is not a valid syntax in SQL SERVER, looks like you're attempting more like MySQL or Oracle PL/SQL.
The BEFORE trigger and NEW-OLD pseudo records do not exist in SQL Server.
Here is a code in sql server you can use :
USE CORE_DATA;
GO
CREATE TRIGGER trg_copy_two_fields
ON dbo.OR_OP
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE t
SET FIXSTIME = i.STIME
FROM dbo.OR_OP t
INNER JOIN inserted i ON t.PrimaryKey = i.PrimaryKey
INNER JOIN deleted d ON d.PrimaryKey = i.PrimaryKey
WHERE d.STIME IS NULL AND i.STIME IS NOT NULL;
END
GO
Replace PrimaryKey with your actual primary key column.
To copy ETIME to FIXETIME, add below code
SET FIXSTIME = i.STIME,
FIXETIME = i.ETIME
I hope this will answer your query, if not let me know more about tool you are using.
Kind Regards,