Ask a Question related to ASP Database, Design and Development.
-
Darren Heinrich #1
Search multiple keywords across multiple fields
Hi,
I'm about halfway through building a search engine using ASP, SQL and
Access.
As part of that search engine I need to search multiple keywords across
multiple fields
So far I've figured out how to split a string into words. From here I could:
Construct an SQL statement of varying length that, using the LIKE and AND
operators. This seems damn hard!
Alternately I could concatenate the multiple fields into a variable or array
then search.
What is best - can anyone provide examples ?
Darren
Darren Heinrich Guest
-
One Search String/Multiple Fields
Hello! What I am trying to do is create a query page for my users that allows them to enter one search string (var=#string#) and then click... -
PHP MySQL search same name in multiple dbase fields
How do I search two fields (e.g., "lastName" and "maidenName") using one name (but can be more than 1 word) so one can find a record for a woman for... -
ANN: InterAKT Site Search - search in multiple tables
Hello, We have just released a new product, MX Site Search, meant to help web developers and designers create a search form in their dynamic... -
SQL Search Multiple Fields ??
James wrote: Yes. Well, just execute this SQL statement using the PHP extension for the SQL server you're using. By the way: how does... -
Access Combo Box search allowing seacr on multiple fields
Question: In a table the first field is the Customer number and the second field is the Customer name. I want to create a single combo box so it... -
Bullschmidt #2
Re: Search multiple keywords across multiple fields
Perhaps something like this might give you some ideas:
If KeywordFromDlg <> "" Then
strSQLWhere = strSQLWhere & " AND ("
strSQLWhere = strSQLWhere & " (1<>1)"
strSQLWhere = strSQLWhere & " OR (Title Like " & Chr(39) & "%" &
KeywordFromDlg & "%" & Chr(39) & ")"
strSQLWhere = strSQLWhere & " OR (Category Like " & Chr(39) & "%" &
KeywordFromDlg & "%" & Chr(39) & ")"
strSQLWhere = strSQLWhere & " OR (Descr Like " & Chr(39) & "%" &
KeywordFromDlg & "%" & Chr(39) & ")"
strSQLWhere = strSQLWhere & ")"
End If
Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
[url]http://www.Bullschmidt.com[/url]
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Bullschmidt Guest
-
Darren Heinrich #3
Re: Search multiple keywords across multiple fields
Gosh not sure I understand all that - can you break it down for me please ?
Thanks
Darren
"Bullschmidt" <paul@bullschmidt.com-nospam> wrote in message
news:%23a6G%23E36DHA.1556@tk2msftngp13.phx.gbl...> Perhaps something like this might give you some ideas:
>
> If KeywordFromDlg <> "" Then
> strSQLWhere = strSQLWhere & " AND ("
> strSQLWhere = strSQLWhere & " (1<>1)"
> strSQLWhere = strSQLWhere & " OR (Title Like " & Chr(39) & "%" &
> KeywordFromDlg & "%" & Chr(39) & ")"
> strSQLWhere = strSQLWhere & " OR (Category Like " & Chr(39) & "%" &
> KeywordFromDlg & "%" & Chr(39) & ")"
> strSQLWhere = strSQLWhere & " OR (Descr Like " & Chr(39) & "%" &
> KeywordFromDlg & "%" & Chr(39) & ")"
> strSQLWhere = strSQLWhere & ")"
> End If
>
> Best regards,
> J. Paul Schmidt, Freelance ASP Web Developer
> [url]http://www.Bullschmidt.com[/url]
> ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
>
>
> *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
> Don't just participate in USENET...get rewarded for it!
Darren Heinrich Guest
-
Bullschmidt #4
Re: Search multiple keywords across multiple fields
Example of searching for keywords separately for each word on multiple
fields. For example with Keywords of Go Back Now one gets the SQL Where
clause of ((Title Like '%Go%') OR (Category Like '%Go%') OR (Descr Like
'%Go%')) OR ((Title Like '%Back%') OR (Category Like '%Back%') OR (Descr
Like '%Back%')) OR ((Title Like '%Now%') OR (Category Like '%Now%') OR
(Descr Like '%Now%')):
'Keywords = Request.Form("Keywords")
Keywords = "Go Back Now"
' Set var.
KeywordsFixedForSQL = Keywords
' Remove any ".
KeywordsFixedForSQL = Replace(KeywordsFixedForSQL, Chr(34), "")
' Double up any single quotes.
KeywordsFixedForSQL = Replace(KeywordsFixedForSQL, "'", "''")
If KeywordsFixedForSQL <> "" Then
' Set var (array of words).
strarrayKeywordsFixedForSQL = Split(KeywordsFixedForSQL, " ")
' Loop thru items (words).
For intItemNum = 0 To UBound(strarrayKeywordsFixedForSQL)
strSQLWhere = strSQLWhere & " OR ("
strSQLWhere = strSQLWhere & "(Title Like " & Chr(39) & "%" &
strarrayKeywordsFixedForSQL(intItemNum) & "%" & Chr(39) & ")"
strSQLWhere = strSQLWhere & " OR (Category Like " & Chr(39) & "%" &
strarrayKeywordsFixedForSQL(intItemNum) & "%" & Chr(39) & ")"
strSQLWhere = strSQLWhere & " OR (Descr Like " & Chr(39) & "%" &
strarrayKeywordsFixedForSQL(intItemNum) & "%" & Chr(39) & ")"
strSQLWhere = strSQLWhere & ")"
Next ' Next intItemNum.
' Remove initial " OR ".
strSQLWhere = Right(strSQLWhere, Len(strSQLWhere) - 4)
End If
Response.Write "strSQLWhere: " & strSQLWhere & "<br><br>"
Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
[url]http://www.Bullschmidt.com[/url]
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Bullschmidt Guest



Reply With Quote

