6

Given a Table with a column col1 like this:

create table MyTest (
    col1 int NULL,
    col2 decimal(7, 2) NULL
);

insert into MyTest values ( 1, 1.1);

Is there a way for a trigger for update to decide which of the following update statements was executed ?

A:

update MyTest set col1 = 3;

B:

update MyTest set col1 = 3, col2 = 1.1;
7

It makes a difference if this is going to be a set-based trigger, or if you are designing it to handle only one row at a time, but this should get you pointed in the right direction.

IF
UPDATE(col1)
AND UPDATE(col2)
AND EXISTS(SELECT * FROM inserted WHERE col1 = 3 AND col2 = 1.1)
BEGIN
    DO STUFF
END

IF 
UPDATE(col1) 
AND EXISTS(SELECT * FROM inserted WHERE col1 = 3)
BEGIN
    DO STUFF
END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.