Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with Trigger Update Question
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00870777
Message ID:
00871312
Vues:
15
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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform