Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 ASP SQL Database Search :: Problems :: Please Help
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Lycaster
New Member

USA
60 Posts

Posted - 16 May 2002 :  11:21:52  Show Profile  Visit Lycaster's Homepage  Send Lycaster an AOL message
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

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 16 May 2002 :  17:35:22  Show Profile  Send ruirib a Yahoo! Message
I don't think I understood what you meant.
Let's consider your example: how many different products have the "Lin" part?

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.36 seconds. Powered By: Snitz Forums 2000 Version 3.4.07