Hi, I am developing a travel agent software, and I am stocked at a search function, I am letting user to search “tour” table either by “depart_day” or “destination” or “tour_name”, I never know user will search by using one of the criteria, or they will use any two of them at the same time, or they will search using all the three criteria. The more criteria they use, they can narrow down the search and get exactly what they want. Below is my plan, but I think this is way too complicated, if I want to expand more criteria for user, the code will be too large, I don’t know if there is some programming language technique especially to solve these kind of problems?
[code]method parameters: pTourName as string = “”, pDepartDay as string = “”, pDestination as string = “”
Dim sql as String
IF pTourName <> “” and pDepartDay = “” and pDestination = “” Then
sql = “SELECT * FROM tour WHERE ‘tour_name’ LIKE '%”+pTourName+"%’;"
ELSEIF pTourName = “” and pDeartDay <>"" and pDestination = “” Then
sql = “SELECT * FROM tour WHERE ‘depart_day’ = “+pDepartDay+”;”
ELSEIF pTourName = “” and pDepartDay = “” and pDestination <> “” Then
sql = “SELECT * FROM tour WHERE ‘pDestination’ = “+pDestination+”;”
ELSEIF pTourName <> “” and pDepartDay <> “” and pDestination = “” Then
sql = “SELECT * FROM tour WHERE ‘tour_name’ LIKE '%”+pTourName+"%’ AND ‘depart_day’ = “+pDepartDay+”;"
ELSEIF pTourName <> “” and pDepartDay = “” and pDestination <> “” Then
sql = “SELECT * FROM tour WHERE ‘tour_name’ LIKE '%”+pTourName+"%’ AND ‘dDestination’ = “+pDestination+”;"
ELSEIF pTourName = “” and pDepartDay <> “” and pDestination <> “” Then
sql = “SELECT * FROM tour WHERE ‘depart_day’ = “+pDepartDay+” AND ‘dDestination’ = “+pDestination+”;”
ELSEIF pTourName <> “” and pDepartDay <> “” and pDestination <> “” Then
sql = “SELECT * FROM tour WHERE ‘tour_name’ LIKE '%”+pTourName+"%’ AND ‘depart_day’ = “+pDepartDay+” AND ‘dDestination’ = “+pDestination+”;"
END IF[/code]