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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a string in an SQL query

Status
Not open for further replies.

Lynus

Technical User
Apr 12, 2003
69
Hi Folks. I am searching threw a database based upon criteria that the user enters. So the user would enter "test" for the search criteria. I set up a string and am calling it searchstringtext. Now my question is are you allowed to use strings in your sql statements. IF so how do you achieve it. Below is a samble of my code.

Set newrec = New ADODB.Recordset
newrec = "SELECT * FROM bugs WHERE dbbugdescription LIKE ('searchstringtext')"

Any help would be greatly appreciated.
Thanks
 
"SELECT * FROM bugs WHERE dbbugdescription LIKE ('" & searchstringtext & "')"
 
don't forget the * or % depending on what database you are connecting to. Otherwise if you want an exact match don't use LIKE

ie
"SELECT * FROM bugs WHERE dbbugdescription LIKE ('%" & searchstringtext & "'%)"
for finding the value in searchstringtext anywhere in dbbugdescription
or
"SELECT * FROM bugs WHERE dbbugdescription LIKE ('" & searchstringtext & "%')"
for only records that dbbugdescription starts with the value in searchstringtext

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top