I am trying to built a free matrimonial site where the homepage holds a simple form with some textboxes & dropdowns and a button for search.
When clicked it takes the visitor to another page along with query strings of all fields.
I used the following stored procedure to show search result.
ALTER PROCEDURE dbo.homesearch
@gender varchar(6),
@age int,
@age2 int,
@religion varchar(50),
@status varchar(11),
@resCountry varchar(50),
@resCity varchar(50)
AS
SELECT *
FROM [users]
WHERE
( ([age] > @age) OR ([age] < @age2) OR
([gender] = @gender) OR ([religion] = @religion) OR
([status] = @status) OR ([resCountry] = @resCountry) OR
([resCity] = @resCity))
RETURN
The problem is I am stuck with OR & AND
if I use OR
then it will show lots of irrelevant result.
if I use AND
then what if any of the search query is empty.
Sorry I am new to this and my question might be too childish for you friends.
Another question if its the best & secure way to do so ? if not then how can I improve it.