Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Super Urgent ASP WhereClause question

Posted on 1998-12-16
6
201 Views
Last Modified: 2013-12-25
hi,
I have a asp question.

I want a search form (i will make it simple here) with 2 input query.
say City, State.
I click on Submit , the criteria strings will be passed to server and run a sql statement and returns the result.
I know how to pass one parameter but don't know how to pass two parameters.

How can I do that?

Please forward any simple sample code and I will granted with 150 points

Thank you very much and have a nice day!

ny971181
0
Comment
Question by:ny971181
6 Comments
 
LVL 1

Expert Comment

by:rajgn
ID: 1857300
What do you mean by passing parameters? Do you mean passing values of City, State to the .asp(from a form) or passing the values as parameters to a stored procedure? can you elaborate this?
0
 
LVL 1

Author Comment

by:ny971181
ID: 1857301
I mean pass them to the .asp file form a form.
I don't use stored procedure in sql server.

thanks

0
 
LVL 1

Expert Comment

by:rajgn
ID: 1857302
Hey ny971181!

Is this question different from the other one?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 6

Accepted Solution

by:
PBall earned 100 total points
ID: 1857303
<searchform.asp>
<html>
:
<form name=frmSearch action='search.asp' method=post>
<input name=txtCity value="">
<select name=selState>
:
<option value='FL'>Florida
:
</select>
:
<input type=submit name=btnNav value='Search'>
</form>
:
</html>

<search.asp>

<%
option explicit

dim city, state

city = request("txtCity")
state = request("selState")
:
strSQL = "SELECT ..... FROM Blah WHERE City = '" & city & "' AND State = '" & state & "' ORDER BY ...."

set rs = server.createobject("adodb.recordset")
rs.open strSQL,"databaseDSN"
:
do while not rs.eof
:
:
  rs.movenext
loop
:

is that what you want?
0
 
LVL 1

Author Comment

by:ny971181
ID: 1857304
In the case you mention, you won't get the right recordset if you don't put in any state because the sqlstatement still has the state = "" in it.
any better idea?


0
 

Expert Comment

by:MagicJ
ID: 1857305
I think u can try this
This is an addition to PBall's answer

dim firstCriteria
dim secCriteria

city = request("txtCity")
state = request("selState")
firstCriteria = ""
secCriteria = ""
if city<> "" then
   firstCriteria= " City = '" & city & "' "
end if
if state <> "" then
   if firstCriteria <> "" then
      secCriteria = " AND State = '" & state & "' "
   else
      secCriteria = " State = '" & state & "' "
   end if
end if

strSQL = "SELECT ..... FROM Blah WHERE " & firstCriteria & secCriteria & " ORDER BY ...."

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question