Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to on Update Trigger
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00897234
Message ID:
00897241
Vues:
14
This message has been marked as the solution to the initial question of the thread.
Kirk,

The UPDATE () only reports whether UPDATE/INSERT action was performed on the column. It doesn't care if value has been changed or not in the process. The records with new values are stored in 'inserted' tables. You can use EXISTS subquery in your INSERT INTO SELECT FROM to check if value actually changed.

>I'm trying to get this trigger to record only when the BeginTime or RoomID change during the update process. If its a rooid change, I want to fill that in in the LastAuditForm field, and same thing on the begintime. My problem is that if always see's the roomID as being updated so that is what gets recorded each time. I think I need to compare it against the new value (if I understand right, the update table hold the old values), but I'm not sure how to to get the new value and compare it.
>
>Thanks for the help.
>
>Kirk
>
>
>
>CREATE TRIGGER [Meetings_Audit_Update] ON dbo.meetings
>  FOR UPDATE
>AS
>declare @tcAction varchar(500)
>set @tcAction='Action '
>
>IF update(begintime) or update(RoomID)
> BEGIN
>  IF update(RoomID)
>     begin
>	INSERT INTO Audit_Meeting
>          (meetingnumber,begintime,endtime,patientID,roomid,actualRoomID,
>               ScheduledBy,BlockMember,LastAuditForm,LastAuditBy,deptID)
>          (SELECT meetingnumber,begintime,endtime,patientID,roomid,actualRoomID,
>               ScheduledBy,BlockMember,'Room Change',dbo.get_login_name(),DeptID from deleted)
>     END
> ELSE
>   BEGIN
>	INSERT INTO Audit_Meeting(meetingnumber,begintime,endtime,patientID,roomid,actualRoomID,
>               ScheduledBy,BlockMember,LastAuditForm,LastAuditBy,deptID)
>        (SELECT meetingnumber,begintime,endtime,patientID,roomid,actualRoomID,
>               ScheduledBy,BlockMember,'Date or Time Change',dbo.get_login_name(),DeptID From deleted)
>   END
>END
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform