Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-01-17 : 09:14:44
|
| Kenneth C. Perkins writes "I have an ASP page with an SQL search that takes a string finds a word in various fields that match it. Unfortunatley it will only take one word at a time, how can I rewrite this to do multiple words as well and, or, and not the way msn does.string is accepted here and set equal to a variable:Dim inputinput=Request.Form("Search")Session("input")=Trim(input)response.redirect("directory.asp")string is now taken and searched for in the databaseDim SQL,keywordskeywords=Session("input")Set dbDirectory = Server.CreateObject("ADODB.Connection")dbDirectory.Open "galaxy"SQL = "SELECT * FROM directory WHERE "SQL=SQL + "LAST_NAME LIKE '%" & keywords & "%'" SQL=SQL + "OR FIRST_NAME LIKE '%" & keywords & "%'" SQL=SQL + "OR MI LIKE '%" & keywords & "%'" SQL=SQL + "OR ADDRESS LIKE '%" & keywords & "%'" SQL=SQL + "OR TOWN LIKE '%" & keywords & "%'" SQL=SQL + "OR STATE LIKE '%" & keywords & "%'" SQL=SQL + "OR ZIPCODE LIKE '%" & keywords & "%'" SQL=SQL + "OR TELEPHONE LIKE '%" & keywords & "%'"SQL=SQL + "OR GUARDIAN1 LIKE '%" & keywords & "%'"SQL=SQL + "OR GUARDIAN2 LIKE '%" & keywords & "%'"SQL=SQL + "OR EMAIL LIKE '%" & keywords & "%'"SQL=SQL + "OR BEEPER LIKE '%" & keywords & "%'"SQL=SQL + "OR CELLPHONE LIKE '%" & keywords & "%'"Set Roster = dbDirectory.Execute(SQL)" |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2003-01-17 : 09:59:01
|
| http://www.sqlteam.com/item.asp?ItemID=2077You can also look into full text search in bol.You might also want to put this in a stored procedureand use a command object to execute for better performance andbetter maintainability. |
 |
|
|
|
|
|