Solved

Super Urgent ASP WhereClause question

Posted on 1998-12-16
6
184 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now