I think I am taking the long way to do this. Does anyone have an suggestions for me how I could clean up this code - it's getting quite long.
This is the process page for an advanced search page for a recruiting site I am doing.
'------------------ CODE START
'.................................
' Associative Array of Field Names
' and Table Names for Searching
'.................................
DIM fieldName(34)
DIM tableName(34)
fieldName(1) = "People_BusinessName"
tableName(1) = "tbl_people"
fieldName(2) = "People_FirstName"
tableName(2) = "tbl_people"
fieldName(3) = "People_LastName"
tableName(3) = "tbl_people"
fieldName(4) = "People_Phone_Home"
tableName(4) = "tbl_people"
fieldName(5) = "People_Phone_Business"
tableName(5) = "tbl_people"
fieldName(6) = "People_Email"
tableName(6) = "tbl_people"
fieldName(7) = "People_Address"
tableName(7) = "tbl_people"
fieldName(8) = "People_City"
tableName(8) = "tbl_people"
fieldName(9) = "People_State"
tableName(9) = "tbl_people"
fieldName(10) = "People_ZipCode"
tableName(10) = "tbl_people"
fieldName(11) = "People_PositionDesired"
tableName(11) = "tbl_people"
fieldName(12) = "People_HourlyRate"
tableName(12) = "tbl_people"
fieldName(13) = "Resume_Title"
tableName(13) = "tbl_resumes"
fieldName(14) = "Resume_Exp_Location1"
tableName(14) = "tbl_resumes"
fieldName(15) = "Resume_Exp_Position1"
tableName(15) = "tbl_resumes"
fieldName(16) = "Resume_Exp_Company1"
tableName(16) = "tbl_resumes"
fieldName(17) = "Resume_Exp_Location2"
tableName(17) = "tbl_resumes"
fieldName(18) = "Resume_Exp_Position2"
tableName(18) = "tbl_resumes"
fieldName(19) = "Resume_Exp_Company2"
tableName(19) = "tbl_resumes"
fieldName(20) = "Resume_Exp_Position3"
tableName(20) = "tbl_resumes"
fieldName(21) = "Resume_Exp_Location3"
tableName(21) = "tbl_resumes"
fieldName(22) = "Resume_Exp_Company3"
tableName(22) = "tbl_resumes"
fieldName(23) = "Resume_Comment"
tableName(23) = "tbl_resumes"
fieldName(24) = "Resume_Job_Wanted"
tableName(24) = "tbl_resumes"
fieldName(25) = "Resume_Salary_Range"
tableName(25) = "tbl_resumes"
fieldName(26) = "Resume_Exp_Resp1"
tableName(26) = "tbl_resumes"
fieldName(27) = "Resume_Exp_Resp2"
tableName(27) = "tbl_resumes"
fieldName(28) = "Resume_Exp_Resp3"
tableName(28) = "tbl_resumes"
fieldName(29) = "Resume_Exp_Comm1"
tableName(29) = "tbl_resumes"
fieldName(30) = "Resume_Exp_Comm2"
tableName(30) = "tbl_resumes"
fieldName(31) = "Resume_Exp_Comm3"
tableName(31) = "tbl_resumes"
fieldName(32) = "targetpay"
tableName(32) = "tbl_resumes"
fieldName(33) = "travelpreference"
tableName(33) = "tbl_resumes"
fieldName(34) = "relocate"
tableName(34) = "tbl_resumes"
'.................................
' Retrieve All Form Variables
'.................................
search_keyword = Request.Form("search_keyword"
job_category = Request.Form("job_category"
search_city = Request.Form("job_category"
search_state = Request.Form("job_category"
search_zip = Request.Form("job_category"
CID = Request.Form("job_category"
EmpType = Request.Form("job_category"
Freshness = Request.Form("job_category"
CMTP = Request.Form("job_category"
minsalary = Request.Form("job_category"
maxsalary = Request.Form("job_category"
ExcludeResumes = Request.Form("job_category"
'.................................
' Build Complex Select Statement!
'.................................
strSQL = "SELECT tbl_people.*, tbl_resumes.* FROM tbl_people, tbl_resumes "
strSQL = strSQL + " WHERE "
'.................................
' Are We Checking For Keywords?
'.................................
IF search_keyword<>"" THEN
' Set Flag
bolAddAnd = true
' Loop through Associative Array
FOR x = 1 to UBound(FieldName)
strSQL = strSQL & tableName(x) & "." & fieldName(x) & " = '" & search_keyword & "' "
IF x<>UBound(FieldName) THEN
strSQL = strSQL + " OR "
END IF
NEXT
'Response.Write(strSQL)
'Response.End()
END IF
'.............................
' Check Categories
'.............................
IF job_category <> "" AND job_category<>"All" THEN
' Set the AND flag
bolAddAnd = true
IF bolAddAnd = true THEN
strSQL = strSQL & " AND tbl_resumes.Category = '" & job_category & "'"
ELSE
strSQL = strSQL & " tbl_resumes.Category = '" & job_category & "'"
END IF
END IF
'.............................
' Check City
'.............................
IF search_city<>"" THEN
bolAddAnd = true
IF bolAddAnd = true THEN
strSQL = strSQL & " AND tbl_people.people_city = '" & search_city & "'"
ELSE
strSQL = strSQL & " tbl_people.people_city = '" & search_city & "'"
END IF
END IF
'.............................
' Check State
'.............................
IF search_state<>"" THEN
bolAddAnd = true
IF bolAddAnd = true THEN
strSQL = strSQL & " AND tbl_people.people_state = '" & search_state & "'"
ELSE
strSQL = strSQL & " tbl_people.people_state = '" & search_state & "'"
END IF
END IF
'---------- END SNIPPET
As you can see, this is going to go ON and ON for about another 20 or 30 fields! Ugh.
I am hoping one of you SQL guru's has a few ideas for me. Although this MAY work (have not tested yet) - I just have this feeling I am coding in a very inefficient manner.
Thanks everyone.
Giovanni
This is the process page for an advanced search page for a recruiting site I am doing.
'------------------ CODE START
'.................................
' Associative Array of Field Names
' and Table Names for Searching
'.................................
DIM fieldName(34)
DIM tableName(34)
fieldName(1) = "People_BusinessName"
tableName(1) = "tbl_people"
fieldName(2) = "People_FirstName"
tableName(2) = "tbl_people"
fieldName(3) = "People_LastName"
tableName(3) = "tbl_people"
fieldName(4) = "People_Phone_Home"
tableName(4) = "tbl_people"
fieldName(5) = "People_Phone_Business"
tableName(5) = "tbl_people"
fieldName(6) = "People_Email"
tableName(6) = "tbl_people"
fieldName(7) = "People_Address"
tableName(7) = "tbl_people"
fieldName(8) = "People_City"
tableName(8) = "tbl_people"
fieldName(9) = "People_State"
tableName(9) = "tbl_people"
fieldName(10) = "People_ZipCode"
tableName(10) = "tbl_people"
fieldName(11) = "People_PositionDesired"
tableName(11) = "tbl_people"
fieldName(12) = "People_HourlyRate"
tableName(12) = "tbl_people"
fieldName(13) = "Resume_Title"
tableName(13) = "tbl_resumes"
fieldName(14) = "Resume_Exp_Location1"
tableName(14) = "tbl_resumes"
fieldName(15) = "Resume_Exp_Position1"
tableName(15) = "tbl_resumes"
fieldName(16) = "Resume_Exp_Company1"
tableName(16) = "tbl_resumes"
fieldName(17) = "Resume_Exp_Location2"
tableName(17) = "tbl_resumes"
fieldName(18) = "Resume_Exp_Position2"
tableName(18) = "tbl_resumes"
fieldName(19) = "Resume_Exp_Company2"
tableName(19) = "tbl_resumes"
fieldName(20) = "Resume_Exp_Position3"
tableName(20) = "tbl_resumes"
fieldName(21) = "Resume_Exp_Location3"
tableName(21) = "tbl_resumes"
fieldName(22) = "Resume_Exp_Company3"
tableName(22) = "tbl_resumes"
fieldName(23) = "Resume_Comment"
tableName(23) = "tbl_resumes"
fieldName(24) = "Resume_Job_Wanted"
tableName(24) = "tbl_resumes"
fieldName(25) = "Resume_Salary_Range"
tableName(25) = "tbl_resumes"
fieldName(26) = "Resume_Exp_Resp1"
tableName(26) = "tbl_resumes"
fieldName(27) = "Resume_Exp_Resp2"
tableName(27) = "tbl_resumes"
fieldName(28) = "Resume_Exp_Resp3"
tableName(28) = "tbl_resumes"
fieldName(29) = "Resume_Exp_Comm1"
tableName(29) = "tbl_resumes"
fieldName(30) = "Resume_Exp_Comm2"
tableName(30) = "tbl_resumes"
fieldName(31) = "Resume_Exp_Comm3"
tableName(31) = "tbl_resumes"
fieldName(32) = "targetpay"
tableName(32) = "tbl_resumes"
fieldName(33) = "travelpreference"
tableName(33) = "tbl_resumes"
fieldName(34) = "relocate"
tableName(34) = "tbl_resumes"
'.................................
' Retrieve All Form Variables
'.................................
search_keyword = Request.Form("search_keyword"
job_category = Request.Form("job_category"
search_city = Request.Form("job_category"
search_state = Request.Form("job_category"
search_zip = Request.Form("job_category"
CID = Request.Form("job_category"
EmpType = Request.Form("job_category"
Freshness = Request.Form("job_category"
CMTP = Request.Form("job_category"
minsalary = Request.Form("job_category"
maxsalary = Request.Form("job_category"
ExcludeResumes = Request.Form("job_category"
'.................................
' Build Complex Select Statement!
'.................................
strSQL = "SELECT tbl_people.*, tbl_resumes.* FROM tbl_people, tbl_resumes "
strSQL = strSQL + " WHERE "
'.................................
' Are We Checking For Keywords?
'.................................
IF search_keyword<>"" THEN
' Set Flag
bolAddAnd = true
' Loop through Associative Array
FOR x = 1 to UBound(FieldName)
strSQL = strSQL & tableName(x) & "." & fieldName(x) & " = '" & search_keyword & "' "
IF x<>UBound(FieldName) THEN
strSQL = strSQL + " OR "
END IF
NEXT
'Response.Write(strSQL)
'Response.End()
END IF
'.............................
' Check Categories
'.............................
IF job_category <> "" AND job_category<>"All" THEN
' Set the AND flag
bolAddAnd = true
IF bolAddAnd = true THEN
strSQL = strSQL & " AND tbl_resumes.Category = '" & job_category & "'"
ELSE
strSQL = strSQL & " tbl_resumes.Category = '" & job_category & "'"
END IF
END IF
'.............................
' Check City
'.............................
IF search_city<>"" THEN
bolAddAnd = true
IF bolAddAnd = true THEN
strSQL = strSQL & " AND tbl_people.people_city = '" & search_city & "'"
ELSE
strSQL = strSQL & " tbl_people.people_city = '" & search_city & "'"
END IF
END IF
'.............................
' Check State
'.............................
IF search_state<>"" THEN
bolAddAnd = true
IF bolAddAnd = true THEN
strSQL = strSQL & " AND tbl_people.people_state = '" & search_state & "'"
ELSE
strSQL = strSQL & " tbl_people.people_state = '" & search_state & "'"
END IF
END IF
'---------- END SNIPPET
As you can see, this is going to go ON and ON for about another 20 or 30 fields! Ugh.
I am hoping one of you SQL guru's has a few ideas for me. Although this MAY work (have not tested yet) - I just have this feeling I am coding in a very inefficient manner.
Thanks everyone.
Giovanni