0

How do I change values of a column in an insert trigger ? In Oracle I can use the following code to change the col1 value to upper case in an INSERT Trigger. How do I do it in SQL Server ?

IF exists (select col1 from inserted where col1 is  NOT NULL )
        begin 
            :NEW.col1:= UPPER(:NEW.col1);
        end 
user3844877
  • 493
  • 4
  • 9
  • 18

1 Answers1

1

Here is one way using an INSTEAD OF trigger.

CREATE TRIGGER MyTrigger ON MyTable INSTEAD OF INSERT AS
    INSERT MyTable(col1, [other columns])
    SELECT UPPER(i.col1)
        , i.[other columns]
    FROM Inserted i
Sean Lange
  • 33,028
  • 3
  • 25
  • 40