CREATE PROCEDURE dbo.MonaStatisticSpecified @AHotelCustomerNumberCSV VARCHAR(100), @AFollowupSubType2CSV VARCHAR(100), @AFromDate DATETIME, @AToDate DATETIME AS
/*
  Created by Kent Johansen, February 2022

*/

SELECT Followup.SubType2, ReservationFollowupXTab.ReferenceNumber, ReservationFollowupXTab.GuestNumber, Personel.UserTypeNumber
FROM FollowUp WITH (NOLOCK)
INNER JOIN Personel WITH (NOLOCK) ON Personel.UserIdNumber = Followup.CreatedBy
INNER JOIN ReservationFollowupXTab WITH (NOLOCK) ON ReservationFollowupXTab.FollowUpNumber = Followup.FollowupNumber
INNER JOIN ReservationMain WITH (NOLOCK) ON ReservationMain.ReferenceNumber = ReservationFollowupXTab.ReferenceNumber
  AND (ISNULL(@AHotelCustomerNumberCSV, '') = '' OR ReservationMain.FkCustomerHotel IN (SELECT Number FROM dbo.iter_intlist_to_table(@AHotelCustomerNumberCSV)))
WHERE ISNULL(Followup.SubType2, 0) > 0
AND (ISNULL(@AFollowupSubType2CSV, '') = '' OR ISNULL(Followup.SubType2, 0) IN (SELECT Number FROM dbo.iter_intlist_to_table(@AFollowupSubType2CSV)))
AND Followup.CreatedDate BETWEEN @AFromDate AND @AToDate