Executed SQL - DECLARE @City varchar(900), @County varchar(900), @Schools varchar(900) , @Style varchar(900), @Agent varchar(900), @Firm varchar(900), @City2 varchar(900), @City3 varchar(900), @County2 varchar(900), @County3 varchar(900)
Set @City = '%' + RTRIM(Replace('[QRY-CITY]','_','-')) + '%'
Set @City2 = '%' + RTRIM(Replace('[QRY-CITY2]','_','-')) + '%'
Set @City3 = '%' + RTRIM(Replace('[QRY-CITY3]','_','-')) + '%'
Set @County = '%' + RTRIM(Replace('[QRY-COUNTY]','_','-')) + '%'
Set @County2 = '%' + RTRIM(Replace('[QRY-COUNTY2]','_','-')) + '%'
Set @County3 = '%' + RTRIM(Replace('[QRY-COUNTY3]','_','-')) + '%'
set @Schools = RTRIM(Replace('[QRY-SCHOOLS]','_','-')) + '%'
Set @Style = '%' + RTRIM(Replace('[QRY-STYLE]','_','-')) + '%'
Set @Agent = '%' + RTRIM(Replace('[QRY-AGENT]','_','-')) + '%'
Set @Firm = '%' + RTRIM(Replace('[QRY-FIRM]','_','-')) + '%'
IF @CITY = '%ANY%' OR @City = '% %' Set @City = '%%'
IF @CITY2 = '%Or City%' OR @City2 = '% %' Set @City2 = @CITY
IF @CITY3 = '%Or City%' OR @City3 = '% %' Set @City3 = @CITY
IF @COUNTY = '%ANY%' OR @County = '% %' Set @County = '%%'
IF @COUNTY2 = '%Or County%' OR @County2 = '% %' Set @County2 = @County
IF @COUNTY3 = '%Or County%' OR @County3 = '% %' Set @County3 = @County
IF @Schools = 'ANY%' OR @Schools = ' %' Set @Schools = '%%'
IF @Style = '%ANY%' Set @Style = '%%'
If @Agent = '%ANY%' Set @Agent = '%%'
If @Firm = '%ANY%' Set @Firm = '%%'
select "mls number", "price listing", "address street number", "address street direction", "address street name", "address city", "#sqft total (numeric)", "area zone code", "#units", "school dist", "firm name", "FriendlyPrice", "#Rooms Unit 1", "#Rooms Unit 2", "#Rooms Unit 3", "#Rooms Unit 4", "#Rooms Unit 5", "#Rooms Unit 6", "#Rooms Unit 7", "#Rooms Unit 8", "#Bedrooms Unit 1", "#Bedrooms Unit 2", "#Bedrooms Unit 3", "#Bedrooms Unit 4", "#Bedrooms Unit 5", "#Bedrooms Unit 6", "#Bedrooms Unit 7", "#Bedrooms Unit 8", "#Baths Unit 1", "#Baths Unit 2", "#Baths Unit 3", "#Baths Unit 4", "#Baths Unit 5", "#Baths Unit 6", "#Baths Unit 7", "#Baths Unit 8" from vMultiFamily
WHERE ("price listing" BETWEEN [QRY-PRICEMIN] AND [QRY-PRICEMAX]) AND ("#sqft total (numeric)" BETWEEN [QRY-SQFTMIN] AND [QRY-SQFTMAX]) AND ("address city" LIKE @City OR "address city" LIKE @City2 OR "address city" LIKE @City3) AND ("area zone code" LIKE @County OR "area zone code" LIKE @County2 OR "area zone code" LIKE @County3) AND "school dist" LIKE @Schools And "style of home" like @Style AND AgentFullName LIKE @Agent AND "firm name" LIKE @Firm Order By "price listing" desc