Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Multiple sql searches
Old 06-14-2007, 01:19 PM Multiple sql searches
Average Talker

Posts: 27
Trades: 0
Hello all!

I am having a hard time getting my database to work properly. I am trying to search multiple rows and return presentations based upon that row. Currently I get the first choice from "FootCare" no matter which option I choose in my form. How do I deliminate these so it searches each one and moves onto the next subject? I am using ASP and using an ACCESS database.

SQL="SELECT Presentations FROM Speakers WHERE Subjects = 'Skeletal';"
SQL="SELECT Presentations FROM Speakers WHERE Subjects = 'Surgical';"
SQL="SELECT Presentations FROM Speakers WHERE Subjects = 'FootCare'"

I think I will have one other bug, but I am not sure if it is connected to this problem.

Thank you!

Last edited by jengiss; 06-14-2007 at 01:33 PM..
jengiss is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-14-2007, 01:23 PM Re: Multiple sql searches
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
The first two lines are ignored, because you keep resetting the value of your SQL variable to a new query. This wipes out what used to be there. You would need to process the query after setting it, before setting it to something different.

That would be silly though. Instead, combine the three queries into one, and combine your where clauses with OR statements.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-14-2007, 02:16 PM Re: Multiple sql searches
Average Talker

Posts: 27
Trades: 0
Okay and that is what I thought the change would be. SO I now have it written:

SQL="SELECT Presentations FROM Speakers WHERE Subjects = 'Skeletal' OR 'Surgical' OR 'FootCare'"

I still get it returning only the first option from FootCare which is say "Blisters" on every option I pick from the drop down.

So I am going to guess that the bug is in this bit of code.

Response.write "<colgroup>"
Response.Write("<table border='1'><tr>")
Response.write "<col width=120>"
Response.write "</colgroup>"


For i = 0 to recordset.Fields.Count - 1
Response.Write("<td>" & recordset(i) & "</td>")

Next

response.Write("</tr></table>")

And I know it is horribly written so if anyone could help me out with this I would appreciate it.

Thank you for your fast response.

Last edited by jengiss; 06-14-2007 at 02:23 PM..
jengiss is offline
Reply With Quote
View Public Profile
 
Old 06-14-2007, 02:24 PM Re: Multiple sql searches
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
For starters, you might want to move on to the next record in the recordset?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-14-2007, 03:27 PM Re: Multiple sql searches
Average Talker

Posts: 27
Trades: 0
Yeah that helped, I rewrote that section of the code that had been butchered one too many times. I now get a list of everything in the database for each time I select an option in the dropdown. I guess the good news is that it works fast!

Thank you for the help. I will revist this new problem tomorrow after some sleep.
jengiss is offline
Reply With Quote
View Public Profile
 
Old 06-15-2007, 03:20 PM Re: Multiple sql searches
Average Talker

Posts: 27
Trades: 0
Okay I have everything working perfectly except when I do my sql search it returns all the results instead of just the one choice I want. Can anyone tell me why my SQL line returns all the options instead of just one value?

Once again I am using ASP and Access:

SQL="SELECT Presentations FROM Speakers WHERE Subjects = 'Skeletal' OR 'Surgical' OR 'FootCare' OR 'DiseaseManagement' OR 'GeneralMedicine' OR 'VaricoseVeins' OR 'BreastCancer' OR 'MedicalMission'"

Thank you for the help!
jengiss is offline
Reply With Quote
View Public Profile
 
Old 06-15-2007, 05:17 PM Re: Multiple sql searches
Average Talker

Posts: 27
Trades: 0
Alright I was making it too complicated. Rethought it and everything works!

Here is a teaser for anyone having the same problem in the future.

SQL="SELECT * FROM Speakers"

If Request.Form("Subjects") = "Skeletal" Then
SQL = SQL & " WHERE Subjects = 'Skeletal'"
End If

If Request.Form("Subjects") = "FootCare" Then
SQL = SQL & " WHERE Subjects = 'FootCare'"
End If

etc....

Good luck
jengiss is offline
Reply With Quote
View Public Profile
 
Old 06-15-2007, 05:34 PM Re: Multiple sql searches
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Good work! I'm glad you figured it out. Let us know if anything else comes up - it's always more interesting to help someone who's actually putting in some effort and learning.

Here's a tip for you: IN. You'll love it, if you can do some string manipulation to make use of it. It's basically a way to shortcut really long OR blends.

SELECT * FROM Speakers WHERE Subjects IN ('Skeletal', 'FootCare', 'Surgical')

Try that, it's the same as the way you're building a long OR clause, only it's a lot easier to work with.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-15-2007, 06:00 PM Re: Multiple sql searches
Average Talker

Posts: 27
Trades: 0
ARGH!! I tried that line and used a semicolon instead of a comma.

Thanks for the tip!
jengiss is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Multiple sql searches
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30858 seconds with 12 queries