Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to on Update Trigger
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00897234
Message ID:
00897241
Views:
15
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--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform