MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old February 10th, 2004, 01:01 PM
dylan2004 dylan2004 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 dylan2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Search and Results using multiple columns

I have a DBTable named Vendors which includes the following columns: CompanyName (Name Here)
SBI (Yes, No)
MBE (Yes, No)
SBI (Yes, No)
WBE (Yes, No)

I'm trying to do a search on Vendors where either SBI or MBE or SBI or WBE is equal to 'yes' and then order by company name.

I'm lost on both the search and the results code.

I'd like to have a drop down for the search like this:

<form name="Search" action="vendor_results.asp" method="post">
<Input type=hidden name="validate" value=1>

Show all Vendors who are: <Select name="?????">
<OPTION value="YES">SBI
<OPTION value="YES">SBE
<OPTION value="Yes">MBE
<OPTION value="Yes">WBE
</select>
<Input type="submit" Value="Go">
</form>


Any ideas on how to make this work would be greatly appreciated.

Reply With Quote
  #2  
Old February 10th, 2004, 10:06 PM
chichian chichian is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Las Vegas
Posts: 12 chichian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m 17 sec
Reputation Power: 0
I think you should send the option values the fieldnames from your tables:

Code:
<form name="Search" action="vendor_results.asp" method="post">
  <input type=hidden name="validate" value=1>
  Show all Vendors who are: 
  <select name="searchfield">
    <option value="SBI">SBI</option>
    <option value="SBE">SBE</option>
    <option value="MBE">MBE</option>
    <option value="WBE">WBE</option>
  </select>
  <input type="submit" value="Go">
</form>


So then you can form your sql querystring easily (with just concatenation) in your "vendor_results.asp". The form of the query will be like:

SELECT CompanyName FROM Vendors WITH (NOLOCK) WHERE <searchfield>='Yes' ORDER BY CompanyName ASC

(or <searchfield>=1 if you used boolean). This amounts to the following code for building the query string.

Code:
sqlquery = "SELECT CompanyName FROM Vendors WITH (NOLOCK) WHERE " & _
Request.Form("searchfield") & "='Yes' ORDER BY CompanyName ASC"


I hope this helps. I am really new to ASP and MS SQL, so good luck. OH YEAH, this works if you want to mutually exclude the options. If you wanted them to be able to have multiple options set to yes (i.e. SBI and WBE set to yes), you'll have to use a different form element and form the query slightly different.

Last edited by chichian : February 10th, 2004 at 10:13 PM.

Reply With Quote
  #3  
Old February 11th, 2004, 09:24 AM
dylan2004 dylan2004 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 dylan2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks!

Thanks - this did help - i had to make a few changes but it works now - greatly appreciated! I also had never heard of the (NOLOCK) command so thanks for that as well.

Here is what I did if anyone wants to see it:

for my search page code i used what chichian suggested:

code:

<form name="Search" action="vendor_results.asp" method="post">
<input type=hidden name="validate" value=1>
Show all Vendors who are:
<select name="searchfield">
<option value="SBI">SBI</option>
<option value="SBE">SBE</option>
<option value="MBE">MBE</option>
<option value="WBE">WBE</option>
</select>
<input type="submit" value="Go">
</form>

And for my search results page I did this:

if request("validate")=1 then
strsearchfield=request("searchfield")
strWhere="WHERE " & _
Request.Form("searchfield") & "='Yes' GROUP BY ID, CompanyName, City, State, Zip"

strSQL = "SELECT COUNT(CompanyName) as resultcount FROM Vendors WITH (NOLOCK) WHERE " & _
Request.Form("searchfield") & "='Yes' GROUP BY ID, CompanyName, City, State, Zip"
Set rsCount = conn.Execute(strSQL)
ReportOnError("Error")

End If

' Retrieve the rows from the database for the users choice
'
Server.Scripttimeout = 64000

strSQL = "SELECT ID, CompanyName, City, State, Zip from Vendors " & strWhere
cmdTemp.commandtext = strSQL
set rsSearch = cmdTemp.execute
ReportOnError("Error Selecting")


%>

<%

do while not rsSearch.eof

strCompanyName = rsSearch("CompanyName")

if isnull (strCompanyName) then
strCompanyName = "&nbsp;"
end if


' Display the rows ' %>



Company Name: <%=rsSearch("CompanyName")%><BR>
(<%=rsSearch("City")%>) <BR>

<%=rsSearch("State")%><BR>

<%=rsSearch("Zip")%><BR>

<A HREF="vendor_info.asp?ID=<%=rsSearch("ID")%>">view</a><BR>

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Search and Results using multiple columns


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway