DECLARE @KeyValue INT

SELECT @KeyValue = KeyValue FROM hotelsetup WHERE SearchKey = 'ShowAllProductsInProductSearch'

IF ISNULL(@KeyValue, 0) = 1
BEGIN
	UPDATE HotelSetup
	SET KeyValue = 1
	WHERE SearchKey = 'ProductSelectShow'
	IF @@ROWCOUNT = 0
		INSERT INTO HotelSetup (SearchKey, LabelName, Keyvalue, TextValue)
		VALUES ('ProductSelectShow', 'Show:', 1, 'All')
	
	DELETE from hotelsetuplog
	where hotelsetupnumber IN (Select hs.HotelsetupNumber FROM hotelsetup hs WHERE SearchKey = 'ShowAllProductsInProductSearch')

	DELETE FROM hotelsetup WHERE SearchKey = 'ShowAllProductsInProductSearch'
END