Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with Trigger Update Question
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00870777
Message ID:
00871312
Views:
16
Hi Kirk,

Even if UPDATE command replaces column value with the value that it has already, the column is considered updated. IOW, if isCompleted=0 and it UPDATE sets it to 0 again, update(isCompleted) will be true. Also, you cannot guaranty that only one record will be affected by UPDATE command. If you don't want to program for that case, check for it end exit trigger.
-- If more than one or none record is updated, do nothing
IF @@ROWCOUNT <> 1
  RETURN
...
if update(begintime) or update(RoomID) or update(isCompleted) or update(isCancelled)
begin
  IF (Select isCompleted from deleted) <> (Select isCompleted from inserted)
  BEGIN
    if EXISTS (Select * from inserted WHERE isCompleted =1)
        set @tcAction='Case has been Completed'
    else
      set @tcAction='Case has been unfinalized.'
  END
end
>Hi Sergey
>
>Thanks for the tip, I hadn't thought about that. For my "current" purposes, it is always acted on a single record for this table, but good information to know as I move forward. So do you think I could do something like:
>
>
>declare @tcAction varchar(500)
>set @tcAction=' '
>
>if update(begintime) or update(RoomID) or update(isCompleted) or update(isCancelled)
>     begin
>	if (Select isCompleted from deleted)=0
>          begin
>           set @tcAction='Case has been Completed'
>        else
>           set @tcAction='Case has been unfinalized.'
>          end
>    end
>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform