private static void SetBoundariesFilter(MainSearchInput data, ref string where) { string AND = ""; if (where.Length > 0) { AND = " AND "; } string template = " ( base.Id in ( SELECT [EntityBaseId] FROM [dbo].[Entity_AddressSummary] where EntityTypeId = 2 AND [Longitude] < {0} and [Longitude] > {1} and [Latitude] < {2} and [Latitude] > {3} ) ) "; var boundaries = SearchServices.GetBoundaries(data, "bounds"); if (boundaries.IsDefined) { where = where + AND + string.Format(template, boundaries.East, boundaries.West, boundaries.North, boundaries.South); } }