alter trigger dbo.tr_Department
on dbo.Department
for insert, update
as 
begin
    set nocount on

    insert into dbo.DepartmentHistory (HistoryType, DepartmentID, Name, Description, ModifiedDate, ModifiedUserName, ModifiedLoggedUserName)
    select case when d.ID is null then 'I' else 'U' end, i.ID, i.Name, i.Description, case when i.ModifiedDate = d.ModifiedDate then getutcdate() else isnull(i.ModifiedDate, getutcdate()) end, i.ModifiedUserName, i.ModifiedLoggedUserName
    from inserted i
        left outer join deleted d on i.ID = d.ID
end