472,353 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Combination Quries

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:
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. 'Search for lastname only
  3. If overall_qual = "" AND location = "" AND grade = "" AND eval_type = "" Then
  4. SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
  5. & " FROM usertbl " _
  6. & " Where lastname like '" & Request.QueryString("lastname") &"' " _
  7. & " ORDER BY user_id ASC"
  8.  
  9.  
  10. 'Search for overall_qual only
  11. ElseIf lastname = "" AND location = "" AND grade = "" AND eval_type = "" Then
  12. SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
  13. & " FROM usertbl " _
  14. & " Where overall_qual like '" & Request.QueryString("overall_qual") &"' " _
  15. & " ORDER BY user_id ASC"
  16.  
  17.  
  18. 'Search for location only
  19. ElseIf lastname = "" AND overall_qual = "" AND grade = "" AND eval_type = "" Then
  20. SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
  21. & " FROM usertbl " _
  22. & " Where location like  '" & Request.QueryString("location") &"' " _
  23. & " ORDER BY user_id ASC"
  24.  
  25.  
  26. 'Search for grade only
  27. ElseIf lastname = "" AND overall_qual = "" AND location = "" AND eval_type = "" Then
  28. SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
  29. & " FROM usertbl " _
  30. & " Where grade like  '" & Request.QueryString("grade") &"' " _
  31. & " ORDER BY user_id ASC"
  32.  
  33.  
  34. 'Search for evaluation type only
  35. ElseIf lastname = "" AND overall_qual = "" AND location = "" AND grade = "" Then
  36. SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type " _
  37. & " FROM usertbl " _
  38. & " Where eval_type like  '" & Request.QueryString("eval_type") &"' " _
  39. & " ORDER BY user_id ASC"
  40.  
  41. 'Search for certs only
  42. ElseIf lastname = "" AND overall_qual = "" AND location = "" AND grade = ""  AND eval_type = "" Then
  43. SQL = "SELECT user_id, lastname, overall_qual, location, grade, eval_Type, existing_certs " _
  44. & " FROM usertbl " _
  45. & " Where existing_certs  '" & Request.QueryString("existing_certs") &"' " _
  46. & " 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
May 22 '07 #1
4 1079
jhardman
3,406 Expert 2GB
Dale,

Here's one way to simplify:
Expand|Select|Wrap|Line Numbers
  1. SQL = "SELECT * FROM usertbl WHERE "
  2. if request("lastName") <> "" then
  3.    SQL = SQL & "lastName LIKE '" & request("lastname") & "' AND "
  4. end if
  5.  
  6. if request("overall_qual") <> "" then
  7.    SQL = SQL & " overall_qual LIKE '" & Request("overall_qual") &"' AND " 
  8. end if
  9.  
  10. 'etc for the rest of the possibilities
  11. 'this will leave your query with a trailing " AND " regardless
  12.  
  13. SQL = left(SQL, len(sql)-4) 'removes trailing AND and space
  14.  
  15. SQL = SQL & "ORDER BY user_id ASC"
  16.  
Let me know if this helps.

Jared
May 22 '07 #2
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
May 22 '07 #3
Okay, got it working with the following:

Expand|Select|Wrap|Line Numbers
  1. if request("lastname") <> "" AND request("overall_qual") <> ""  AND request("eval_type") <> ""  AND request("existing_certs")  <> "" then
  2.    SQL = SQL & " (location LIKE '" & Request("location") &"') AND (grade LIKE '" & Request("grade") &"') AND " 
  3. end if
Another question though: how do I use wildcards in the query? I've tried this:


Expand|Select|Wrap|Line Numbers
  1. if request("existing_certs") <> "" then
  2.    SQL = SQL & " existing_certs LIKE '" & Request("%existing_certs%") &"' AND " 
  3. end if
But having no luck.
May 22 '07 #4
jhardman
3,406 Expert 2GB
It's been a while since I tried, but if I remember it should be instead of the single quotes:
Expand|Select|Wrap|Line Numbers
  1.  SQL = SQL & " existing_certs LIKE %" & Request("existing_certs") &"%"
  2.  
Jared
May 24 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
1
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...
3
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...
1
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...
6
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...
13
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...
1
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...
3
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,...
3
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...
0
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...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
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...
0
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...
0
hi
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...
0
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...
0
Oralloy
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...
0
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....
0
BLUEPANDA
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.