IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.ReservationRoomLineAllocationLocked') AND OBJECTPROPERTY(id, N'IsTrigger') = 1) DROP TRIGGER dbo.ReservationRoomLineAllocationLocked 
GO
CREATE TRIGGER ReservationRoomLineAllocationLocked ON dbo.RESERVATIONROOMLINE 
FOR INSERT, UPDATE
AS
/*
    Created by Jacob Pedersen 2005

    Description: Make sure AllocationLocked is set to 0 if room is deallocated

    20060601 JP BUG: problem when changing roomnumber for more than one row
*/
/*
IF NOT UPDATE(RoomNumber) -- no need to do anything if roomnumber has not been affected
  RETURN
ELSE
  UPDATE ReservationRoomLine SET AllocationLocked=0 WHERE RoomNumber IS NULL AND LineNumber = (SELECT LineNumber FROM Inserted)
*/

IF UPDATE(RoomNumber) -- no need to do anything if roomnumber has not been affected
  UPDATE ReservationRoomLine SET AllocationLocked=0 WHERE RoomNumber IS NULL AND LineNumber IN (SELECT LineNumber FROM Inserted)
