Forum Moderators: open
arrTemp = Split(strSearch)
strSearch = arrTemp(1) & "*" & arrTemp(0)
This works fine. However, my problem is that I cannot figure out how/where to insert it into the code so that it ONLY does the search if we get 0 results.
How the code works is that it does this little scripty thing at the beginning ...
Public Function FindMatchingWidget(strSearch)
Dim strSQL
strSQL = "SELECT DISTINCT Widget FROM tblMAIN WHERE Widget " & "LIKE '%#s#%' ORDER BY WIDGETS ASC"
strSQL = Replace(strSQL, "#s#", EscapeSQL(strSearch))
FindMatchingWidget = PerformSQL(strSQL)
End Function
The PerformSQL function is a bit larger :) But what it does is return a sentinel (array[0,0] = -1) if the results are 0; or a tuple (?) if it is successful.
So, my question: If this thing returns a sentinel ... how do i figure that out and then send the query again.
My main problem is that i'm not sure *what* this performSQL thing actually returns. <sigh>
My apologies if this isn't clear ... or if it is beyond the scope of what this particular forum is for.
Thanks in advance for any pointers towards an answer!
You are trying to get results in a Database search that matches "word1 word2" or "word2 word1" and you are unclear how to change the SQL to get the two different searches.
how I would handle that is to split the search terms like you did, then query the database with:
SELECT * FROM tblMAIN WHERE Widget LIKE '%word1 word2%'
then do the same for "word2 word1" then search each word individually.
You can work out a way to prevent dupe results later, but this would get you maximum search for minimal terms.
Hopefully that helps.
Public Function FindMatchingWidget(strSearch)
Dim strSQL
strSQL = "SELECT DISTINCT Widget FROM tblMAIN WHERE Widget LIKE '%#s#%' ORDER BY WIDGETS ASC"
strSQL = Replace(strSQL, "#s#", strSearch)
FindMatchingWidget = PerformSQL(strSQL)
End Function
Now, if i understand this at all, i'm simply manufacturing a string (strSQL)to send to the database as a query.
I then set the return value of this function to be whatever the results of the query are.
What I am interested in doing is if this query comes up as nothing, to redo my search and change criteria. Now, the manufacture of a "nothing" result happens like this down in the PerformSQL function, whenever it gets 0 (such as no matching results, or string length of 0) it calls this function, sets PerformSQL to this value, and then exits the PerformSQL function:
Private Function GetSentinelArray
Dim avarResults(1,1)
avarResults(0,0) = -1
GetSentinelArray = avarResults
End Function
Now, my question is, what is the value of "FindMatchingWidget = PerformSQL(strSQL)" when PerformSQL(strSQL) is forced to call "GetSentinelArray"?
The reason I am asking is so that i can put something like this in:
If PerformSQL(SQL) = THE ANSWER Then
Change up search terms
Redo Query
End If
I have never messed with SQL before ... and I'm just migrating over from C to VBscript, so, i apologize if this is still a bit unclear.