I'm building my first query form in ASP and it's going to be a combination search form. My search form has the following fields: lastname, qualification, location, grade, certifications, and eval_type.
I'm a newbie to ASP so this is probably not the way to be doing this, but here's what I have so far: - <%
-
'Search for lastname only
-
If overall_qual = "" AND location = "" AND grade = "" AND eval_type = "" Then
-
SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
-
& " FROM usertbl " _
-
& " Where lastname like '" & Request.QueryString("lastname") &"' " _
-
& " ORDER BY user_id ASC"
-
-
-
'Search for overall_qual only
-
ElseIf lastname = "" AND location = "" AND grade = "" AND eval_type = "" Then
-
SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
-
& " FROM usertbl " _
-
& " Where overall_qual like '" & Request.QueryString("overall_qual") &"' " _
-
& " ORDER BY user_id ASC"
-
-
-
'Search for location only
-
ElseIf lastname = "" AND overall_qual = "" AND grade = "" AND eval_type = "" Then
-
SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
-
& " FROM usertbl " _
-
& " Where location like '" & Request.QueryString("location") &"' " _
-
& " ORDER BY user_id ASC"
-
-
-
'Search for grade only
-
ElseIf lastname = "" AND overall_qual = "" AND location = "" AND eval_type = "" Then
-
SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
-
& " FROM usertbl " _
-
& " Where grade like '" & Request.QueryString("grade") &"' " _
-
& " ORDER BY user_id ASC"
-
-
-
'Search for evaluation type only
-
ElseIf lastname = "" AND overall_qual = "" AND location = "" AND grade = "" Then
-
SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
-
& " FROM usertbl " _
-
& " Where eval_type like '" & Request.QueryString("eval_type") &"' " _
-
& " ORDER BY user_id ASC"
-
-
'Search for certs only
-
ElseIf lastname = "" AND overall_qual = "" AND location = "" AND grade = "" AND eval_type = "" Then
-
SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type, existing_certs " _
-
& " FROM usertbl " _
-
& " Where existing_certs '" & Request.QueryString("existing_certs") &"' " _
-
& " ORDER BY user_id ASC"
I have to allow the user to search on just one field by itself, or a combination of fields as well.
The first three if/elseif statements are working, but the fourth on down don't work and I assume it's because I haven't grouped (?) the search terms? Any help on grouping these together would be appreciated.
Thanks,
Dale
4 1079
Dale,
Here's one way to simplify: -
SQL = "SELECT * FROM usertbl WHERE "
-
if request("lastName") <> "" then
-
SQL = SQL & "lastName LIKE '" & request("lastname") & "' AND "
-
end if
-
-
if request("overall_qual") <> "" then
-
SQL = SQL & " overall_qual LIKE '" & Request("overall_qual") &"' AND "
-
end if
-
-
'etc for the rest of the possibilities
-
'this will leave your query with a trailing " AND " regardless
-
-
SQL = left(SQL, len(sql)-4) 'removes trailing AND and space
-
-
SQL = SQL & "ORDER BY user_id ASC"
-
Let me know if this helps.
Jared
Thanks for suggestions Jared. I like your style. Now I'm trying to combine the following queries, but am getting an error message:
if (request("lastname") AND request("overall_qual") AND request("eval_type") AND request("existing_certs") ) <> "" then
SQL = SQL & " (location LIKE '" & Request("location") AND grade LIKE '" & Request("grade")) &"' AND "
end if
Thanks,
Dale
Okay, got it working with the following: - if request("lastname") <> "" AND request("overall_qual") <> "" AND request("eval_type") <> "" AND request("existing_certs") <> "" then
-
SQL = SQL & " (location LIKE '" & Request("location") &"') AND (grade LIKE '" & Request("grade") &"') AND "
-
end if
Another question though: how do I use wildcards in the query? I've tried this: - if request("existing_certs") <> "" then
-
SQL = SQL & " existing_certs LIKE '" & Request("%existing_certs%") &"' AND "
-
end if
But having no luck.
It's been a while since I tried, but if I remember it should be instead of the single quotes: - SQL = SQL & " existing_certs LIKE %" & Request("existing_certs") &"%"
-
Jared
Sign in to post your reply or Sign up for a free account.
Similar topics
by: David Walker |
last post by:
Hi
I've been doing a site in css recently, and have come across the problem of
IE not allowing text to be selected. The problem is, sometimes it...
|
by: Bo Xu |
last post by:
Object of Combination
By Bo Xu
Introduction
A combination of n things, taken s at a time, often referred as an
s-combination out of n, is a way...
|
by: gdogg1587 |
last post by:
Greetings.
I'm working on a program that will "descramble" words. Think of a word
scramble game where there is a list of characters, and several...
|
by: Diogo Alves - Software Developer |
last post by:
I'm tring to override the combination all the combination like this one Ctrl
+ Shift + . I just can't catch it... I have already done this
for ctrl...
|
by: aka_eu |
last post by:
I have this problem.
I'm trying to get all the valid combination C(N,K) that pass one
condition.
For example C(5,3) can use in any combination...
|
by: Mohammad Omer |
last post by:
Hi,
I am working on SDI base application using vs2k5. I need to perform
some task on combination of keys (link ctrl+v). I wrote WM_KEYDOWN...
|
by: pukhton |
last post by:
Hi all
Just have a question about Access Quries.
I want to create a query where I have to count the number of medication has been given on...
|
by: rengaraj |
last post by:
hi frens
I want to know some information/ explaination from SQL.. I want to know about join queries, subquries, timestamps, date_part, date_trunc,...
|
by: santhosh1986 |
last post by:
hi:
To be honest i am just new to oracle..but i know little bit in mysql..so can anyone help me buy sending basic quries and also describtion abt...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
| |