CREATE PROCEDURE dbo.RoomTypeDifferentialUpdateLogInfo @AFromDate DATETIME, @AToDate DATETIME AS
/*

  Created by Kent Johansen, Septemper 2017
  Changes:
    KJ 20171204: Ext: Get log per DifferentialType


*/
SET NOCOUNT ON

SELECT dtRange.IndividualDate AS View_DateStamp, MAX(RoomTypeDifferentialUpdateLog.rtdulId) AS View_Id, 
ISNULL(RoomTypeDifferentialUpdateLog.ShowRoomOption, 0) AS ShowRoomOption, 0 AS DifferentialType
FROM RoomTypeDifferentialUpdateLog WITH (NOLOCK) 
INNER JOIN RoomTypeDifferentialUpdateLogXTab WITH (NOLOCK) ON RoomTypeDifferentialUpdateLogXTab.FK_RTDifferentialUpdateLogId = RoomTypeDifferentialUpdateLog.rtdulId
  AND RoomTypeDifferentialUpdateLogXTab.ForeignIdType = 0
INNER JOIN RoomTypeDifferential WITH (NOLOCK) ON RoomTypeDifferential.Id = RoomTypeDifferentialUpdateLogXTab.FK_ForeignId
  AND RoomTypeDifferential.DifferentialType = 0
CROSS APPLY dbo.DateRange(RoomTypeDifferentialUpdateLog.FromDate, RoomTypeDifferentialUpdateLog.EndDate, RoomTypeDifferentialUpdateLog.rtdulId) AS dtRange
WHERE dtRange.IndividualDate BETWEEN @AFromdate AND @ATodate
GROUP BY dtRange.IndividualDate, ISNULL(RoomTypeDifferentialUpdateLog.ShowRoomOption, 0)
UNION
SELECT dtRange.IndividualDate AS View_DateStamp, MAX(RoomTypeDifferentialUpdateLog.rtdulId) AS View_Id, 
ISNULL(RoomTypeDifferentialUpdateLog.ShowRoomOption, 0) AS ShowRoomOption, 1 AS DifferentialType
FROM RoomTypeDifferentialUpdateLog WITH (NOLOCK) 
INNER JOIN RoomTypeDifferentialUpdateLogXTab WITH (NOLOCK) ON RoomTypeDifferentialUpdateLogXTab.FK_RTDifferentialUpdateLogId = RoomTypeDifferentialUpdateLog.rtdulId
  AND RoomTypeDifferentialUpdateLogXTab.ForeignIdType = 0
INNER JOIN RoomTypeDifferential WITH (NOLOCK) ON RoomTypeDifferential.Id = RoomTypeDifferentialUpdateLogXTab.FK_ForeignId
  AND RoomTypeDifferential.DifferentialType = 1
CROSS APPLY dbo.DateRange(RoomTypeDifferentialUpdateLog.FromDate, RoomTypeDifferentialUpdateLog.EndDate, RoomTypeDifferentialUpdateLog.rtdulId) AS dtRange
WHERE dtRange.IndividualDate BETWEEN @AFromdate AND @ATodate
GROUP BY dtRange.IndividualDate, ISNULL(RoomTypeDifferentialUpdateLog.ShowRoomOption, 0)