I have setup what I think to be a pretty advanced Keyword(s) SQL Database Search. I get no errors, but for some reason my results are a little buggy.
Here is an example:
Let's say I do a search for "Actuators, Linear" The results bring back all products that are associated with "Actuators, Linear". That’s great, but when I do a Search for "Lin" as an abbreviation for "Actuators, Linear", I get duplicate records in my results. These duplicate records have some logic. For every instance of "Lin" (Lets say there were 3) the same record displays in the results 3 times. So you can see where I have been a bit confused on what is going on.
Here is the code:
"Keyword" is the value from the text field.
<%
If (Request("Keyword") <> "") Then
sSQL = "SELECT Products.Mn_acct, Products.Mn_srt_ord, Products.Mn_coname, Products.Mn_div_nm, Products.Mn_address, "
sSQL = sSQL & "Products.Mn_city, Products.Mn_st_code, Products.Mn_zp_code, Products.Mn_cnt_cod, Products.Mn_cntr_na, Products.Mn_phone_v, "
sSQL = sSQL & "Products.Mn_phone_f, Products.Mn_email, Products.Mn_i_addr, Products.Mn_web_hl, Products.Mn_sls_off, Products.Mn_lst_prd, "
sSQL = sSQL & "Products.Mn_trf_stp, Products.Mn_ft_stp, Products.Mn_ad_ind, Products.Mn_ad_eq, Products.Mn_web_log, Products.Mn_log_flg, Products.Mn_log_nme, "
sSQL = sSQL & "Products.Mn_ad_flg, Products.Mn_pr_lstf, Products.Mn_b_ad_fg, Products.Mn_s_ad_fg, Products.Mn_enhn_fg, "
sSQL = sSQL & "Products.Mn_miad_cd, Products.Mn_miad_na, Products.Mn_bnad_na, ProductInfo.Mn_acct AS CompanyID, "
sSQL = sSQL & "ProductInfo.Pc_prd_cd AS ProductCodeID, ProductInfo.Pc_descrip AS ProductCode "
sSQL = sSQL & "FROM Products INNER JOIN Products ProductInfo ON Products.Mn_acct = ProductInfo.Mn_acct "
sSQL = sSQL & "WHERE (Products.Mn_srt_ord = '1') AND (ProductInfo.Pc_prd_cd > ' ') ORDER BY Products.Mn_coname ASC"
Set oData = Server.CreateObject("ADODB.Recordset")
oData.ActiveConnection = Application.Value("DSN")
oData.Source = sSQL
oData.CursorType = 0
oData.CursorLocation = 3
oData.LockType = 3
oData.Open()
Function BuildFilter(Fields(), sKeyword)
' Local Variables
Dim strContent
Dim strkeywords
Dim intChar
Dim i
strkeywords = sKeyword
If Left(Trim(strkeywords), 1) = """" AND Right(Trim(strkeywords), 1) = """" Then
strkeywords = Mid(strkeywords, 2, Len(strkeywords) - 2)
For i = 0 to UBound(Fields)
strContent = strContent & Fields(i) & " LIKE '%" & strkeywords & "%' OR "
Next
Else
Do
If (InStr(Trim(strkeywords), " ")) Then intChar = InStr(strkeywords, " ") Else intChar = Len(Trim(strkeywords)) + 1
For i = 0 to UBound(Fields)
If intChar > 2 Then strContent = strContent & Fields(i) & " LIKE '%" & Mid(strkeywords, 1, intChar - 1) & "%' OR "
Next
strkeywords = Mid(strkeywords, intChar + 1, Len(strkeywords))
Loop While Trim(strkeywords) <> ""
End If
If strContent <> "" Then strContent = "(" & Mid(strContent, 1, Len(strContent) - 4) & ")" Else strContent = "(UpdSectionGUID = '')"
' Write strContent
BuildFilter = strContent
End Function
Function RemComment(strComment, strStart, strFinish)
Dim strContent
Dim intStart
Dim intFinish
intStart = inStr(1, strComment, strStart)
If intStart <> 0 Then
intFinish = inStr(intStart, strComment, StrFinish)
If intFinish <> 0 Then
strContent = Mid(strComment, 1, intStart - 1) & Mid(strComment, intFinish + 1)
Else
strContent = Mid(strComment, 1, intStart - 1)
End If
Else
strContent = strComment
End If
RemComment = strContent
End Function
sKeyword = Trim(Request("Keyword"))
sFilter = BuildFilter(Array("ProductCode"), sKeyword)
oData.Filter = sFilter
End If
%>
Thanks in advance for any help!
Jared Wuliger
jared@oxcyon.com
www.oxcyon.com