DECLARE @WhereCond varchar(128) IF (@Book = '') OR (@Book IS NULL) OR (RTRIM(@Book) = 'ALL' ) SET @WhereCond = "%" ELSE SET @WhereCond = RTRIM(@Book) SELECT * INTO #ASTRA_BOOK FROM #ASTRA_ALL WHERE [Primary Reference] LIKE @WhereCond AND ( (@startdate IS NULL) OR (@startdate = '') or (DateColumn >=@startdate) ) AND ( (@enddate IS NULL) OR (@enddate = '') OR (DateColumn <= @endate) )Once more, please enclose code between < pre> and < /pre> (w/o spaces) tags because it preserves code formatting and makes it easier to read.