CREATE FUNCTION dbo.Setting(@SearchKey VARCHAR(60), @HotelCustomerNumber INTEGER, @DefaultValue VARCHAR(768))
RETURNS VARCHAR(768) AS
/*
  DESC: Function which returns a hotel setting

  LOG:
  20060518 JP: Created
*/
BEGIN 
  DECLARE
  @Result VARCHAR(768)

  IF @HotelCustomerNumber > 0
    SELECT @Result = KeyValue FROM HotelSetupValue WITH (NOLOCK) INNER JOIN HotelSetupValueXTab WITH (NOLOCK) ON CustomerNumber=@HotelCustomerNumber AND HotelSetupNumber = (SELECT HotelSetupNumber FROM HotelSetup WITH (NOLOCK) WHERE SearchKey Like @SearchKey)
  IF (@@rowcount = 0) OR (@HotelCustomerNumber < 1)
    SELECT @Result = KeyValue FROM HotelSetup WITH (NOLOCK) WHERE SearchKey Like @SearchKey

  RETURN @Result
END

