Solved

Super Urgent ASP WhereClause question

Posted on 1998-12-16
6
206 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to dynamically set the form action using jQuery.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

685 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