Create PROCEDURE [dbo].[OnlineCampaignCode] @TextId VARCHAR(50), @CampcodeId INT, @HotelNumber INT AS

--Created TBU 20141028

--Last Changed

SELECT TOP 1 ccd.PK_CampaignCode, ccd.DiscountType, IsNull(ccd.Value,0) AS DiscountPct, IsNull(cch.DiscountCustomerType,0), IsNull(FK_ProductNumber,0) AS ProductNumber,
FromDate, ToDate, IsNull(ProductName, 0) AS ProductName, IsNull(prod.MiniMumDays, 0) AS MinDays, IsNull(prod.MaximumDays, 0) AS MaxDays, IsNull(cc.period, 0) AS Period 
FROM CampaignCodes cc WITH (NOLOCK) 
INNER JOIN CampaignCodesDiscount ccd WITH (NOLOCK) ON cc.PK_CampaignCode = ccd.PK_CampaignCode 
INNER JOIN CampaignCodesHotel cch WITH (NOLOCK) ON cc.PK_CampaignCode = cch.PK_CampaignCode 
LEFT JOIN products prod WITH (NOLOCK) on prod.ProductNumber = FK_ProductNumber 
WHERE (LOWER(cc.[Text]) = @TextId OR (cc.PK_CampaignCode > 0 AND cc.PK_CampaignCode =@CampcodeId))          
AND ( (cc.ToDate > GETDATE() AND cc.period = 1) OR  (cc.period = 0) ) 
AND DiscountType IN (0,1) 
AND cch.FK_HotelCustomerNumber IN (SELECT CustomerNumber FROM Customer WITH (NOLOCK) WHERE HotelNumber = @HotelNumber)


