Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL strings for a form

Status
Not open for further replies.

tazzer

Technical User
May 3, 2001
11
0
0
GB
Hi,

I'm a first-time ASP user. I've created a search form which accepts a value belonging to a field called Surname which brings up a table of numbers. Is there any way to include the field FirstName in the SQL string so that a user must type in both surname and first name before getting the result? I've heard that InStrings are the answer but I can find no info on them.

My code used is;


sql = "SELECT * FROM Internal WHERE Surname LIKE '"
sql = sql & request.form ("txtSurname") & "%'"

Please help.



 
If I understand you correctly, you want the user to enter the SURNAME and the FIRSTNAME and then search for records that match both of thm.

Get the user to enter the FIRSTNAME and then modify your SQL statement to the following:

sql = "SELECT * FROM Internal WHERE Surname LIKE '"
sql = sql & request.form ("txtSurname") & "%' AND"
sql = sql & "Firstname LIKE '" & request.form("txtFirstName") & "%'" Mise Le Meas,

Mighty :)
 
A good practice is to escape the arguments for your SQL statements so that the code doesn't crash when you substitute special characters in the argument.

E.g.

sql = sql & "Firstname LIKE '" & Replace(request.form("txtFirstName"), "'", "''") & "%'"
Yours,

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top