CREATE PROCEDURE dbo.OnlineDemandedArrangement @Referencenumber  INT AS
SET NOCOUNT ON
/*
    Created by Troels Buch Juni 2008

    Changes: N/A


    NOTES: 	- 

    Last changed:
    AV 2008 0929 Only Select optinal wares....
    AV 2008 0923 removed code for optional wares again
    AV 2008 0923 dont select the optional wares

*/

SELECT DISTINCT ArrangementLines.ArrangementLineNumber, ArrangementLines.Date, ArrangementLines.Time, ArrangementLines.Pieces,ArrangementLines.WareText,
ArrangementLines.Price,ArrangementLines.TotalPrice,ArrangementLines.PlaceText  FROM ArrangementLines WITH (NOLOCK) INNER JOIN
ArrangementReservationsXTab WITH (NOLOCK) ON ArrangementLines.ArrangementLineNumber = ArrangementReservationsXTab.ArrangementLineNumber
LEFT OUTER JOIN ArrangementRoomXTab WITH (NOLOCK) ON ArrangementRoomXTab.ArrangementLineNumber = ArrangementLines.ArrangementLineNumber
INNER JOIN RecurringPatternWareXTab WITH (NOLOCK) ON ArrangementLines.WareNumber = RecurringPatternWareXTab.FK_WareNumber
INNER JOIN RecurringRule WITH (NOLOCK) ON RecurringRule.FK_RecurringPatternID = RecurringPatternWareXTab.FK_RecurringPatternID
WHERE Referencenumber = @Referencenumber
AND ArrangementRoomXTab.ArrangementLineNumber IS NULL
AND RecurringPatternWareXTab.FK_RecurringPatternID NOT IN (SELECT FK_RecurringPatternID FROM RecurringRule WITH (NOLOCK) WHERE RuleType = 17)
