CREATE VIEW ActivityHistoryView( AccountId, ActivityDate, ActivitySubtype, ActivityType, AlternateDetailId
	, CallDisposition, CallDurationInSeconds, CallObject, CallType, ConnectionReceivedId, ConnectionSentId
	, Description, Division, DurationInMinutes, EndDateTime, IsAllDayEvent, IsClosed, IsDeleted, IsHighPriority
	, IsOnLineMeeting, IsReminderSet, IsTask, IsVisibleInSelfService, Location, OwnerId, PrimaryAccountId
	, PrimaryWhoId, Priority, ReminderDateTime, StartDateTime, Status, Subject, WhatId, WhoId)
AS
SELECT
	AccountId, ActivityDate, TaskSubtype AS ActivitySubtype, 'Task' AS ActivityType, null AS AlternateDetailId
	, CallDisposition, CallDurationInSeconds, CallObject, CallType, null AS ConnectionReceivedId, null AS ConnectionReceivedId
	, Description, null AS Division, null AS DurationInMinutes, null AS EndDateTime, null AS IsAllDayEvent, IsClosed, IsDeleted, IsHighPriority
	, null AS IsOnLineMeeting, IsReminderSet, 1 AS IsTask, null AS IsVisibleInSelfService, null AS Location, OwnerId, AccountId AS PrimaryAccountId
	, WhoId AS PrimaryWhoId, null AS Priority, ReminderDateTime, null AS StartDateTime, Status, Subject, WhatId, WhoId
FROM Task
UNION ALL
SELECT
	AccountId, ActivityDate, EventSubType AS ActivitySubtype, 'Event' AS ActivityType, null AS AlternateDetailId
	, null AS CallDisposition, null AS CallDurationInSeconds, null AS CallObject, null AS CallType, null AS ConnectionReceivedId, null AS ConnectionReceivedId
	, Description, null AS Division, DurationInMinutes, EndDateTime, IsAllDayEvent, null AS IsClosed, IsDeleted, null AS IsHighPriority
	, null AS IsOnLineMeeting, IsReminderSet, 0 AS IsTask, null AS IsVisibleInSelfService, Location, OwnerId, AccountId AS PrimaryAccountId
	, Whoid AS PrimaryWhoId, null AS Priority, ReminderDateTime, StartDateTime, null AS Status, Subject, WhatId, WhoId
FROM Event



