Flo
Flo

Reputation: 335

Converting an Oracle trigger to a SQL Server trigger

I've got this trigger in Oracle and need to convert it to SQL Server but I have no clue about SQL Server .

Maybe someone here knows how to convert this trigger?

CREATE OR REPLACE TRIGGER tr_u_gesamtstatus_datum
 BEFORE
  UPDATE
 ON anmeld_x
REFERENCING NEW AS NEW OLD AS OLD
 FOR EACH ROW
WHEN (new.gesamt_status != old.gesamt_status)
begin
  :new.gesamt_status_datum := sysdate;
end;

Upvotes: 1

Views: 481

Answers (1)

Ankit Bajpai
Ankit Bajpai

Reputation: 13509

You may try below -

CREATE TRIGGER tr_u_gesamtstatus_datum
ON anmeld_x
AFTER UPDATE 
AS
UPDATE A
SET gesamt_status_datum = CASE WHEN I.gesamt_status <> A.gesamt_status
                                    THEN GETDATE()
                          END
FROM anmeld_x A
INNER JOIN inserted AS I ON I.key_col = A.key_col   -- Here key_col is your primary key column.

Upvotes: 1

Related Questions