

CREATE PROCEDURE DBO.GetDiscountRate @ReferenceNumber int, @GuestNumber Smallint, @AddressTypeNumber tinyint, @DiscountTypeNumber tinyint, @DiscountRate float output   AS
SET NOCOUNT ON

-- KJ20060117: Added PayTvDiscount (The PayTvDiscount field in ReservationAddress is added in version 3.36)
--Sidst rettet af Klaus Stenå den 9/11-2001

Declare @AllDiscount float
Declare @RoomDiscount float
Declare @HallDiscount float
Declare @MeetingDiscount float
Declare @PhoneDiscount float
Declare @PayTvDiscount float

Select 
  @RoomDiscount = RoomDiscountRate, 
  @HallDiscount = HallDiscountRate, 
  @MeetingDiscount = MeetingDiscountRate, 
  @PhoneDiscount = PhoneDiscountRate, 
  @AllDiscount = DiscountRate,
  @PayTvDiscount = PayTvDiscount
From Reservationaddress WITH (NOLOCK) where AddressType = @AddressTypeNumber and AddressNumber in 
  (Select AddressNumber From  ReservationAddressXTab WITH (NOLOCK) Where ReferenceNumber = @ReferenceNumber AND GuestNumber = @GuestNumber)

if @DiscountTypeNumber = 0
  SET @DiscountRate = @AllDiscount
else
if @DiscountTypeNumber = 1
    SET @DiscountRate = @RoomDiscount
else
if @DiscountTypeNumber = 2
    SET @DiscountRate = @HallDiscount
else
if @DiscountTypeNumber = 3
    SET @DiscountRate = @MeetingDiscount
else
if @DiscountTypeNumber = 4
    SET @DiscountRate = @PhoneDiscount
else
if @DiscountTypeNumber = 5
    SET @DiscountRate = @PayTvDiscount

if IsNull(@DiscountRate,0)=0 SET @DiscountRate = 0

