Solved

Super Urgent ASP WhereClause question

Posted on 1998-12-16
6
196 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
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.

 
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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
increase words that display in widget 6 77
tomcat startup error 5 65
maps stopped work unsure why 7 34
Full width video doesn't shrink on mobile- wordpress, divi 8 47
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 …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

810 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