Forum Moderators: open

Message Too Old, No Replies

VBScript & SQL question

Need some help finding out what functions return

         

rockym

8:46 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



Not positive if this is the right forum, but I didn't see a particular forum that matched.
You guys have always been a great help in the past (i lurk mainly, hardly ever post) and i'm wondering if i could get a bit more advice. :)
Basically:
First off, I didn't write the site (i'm a newbie! :)) so i'm not sure how all of this works.
The situation is that I have a vbscript search that is querying a SQL database and returning the results. Common deal. :)
However, what I would like to do is manipulate the search query that the user enters *only* if the results returned are 0.
Example, a user searches for "White Widgets" but we don't have that listed (b/c our database sorts them as "Widgets*White") so I want the script to see .. "Hey! There are no results ... lets do this!" And then proceed to flip the word around and insert an asterisk.
The code i'm using for the split is:

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!

too much information

9:35 pm on Jan 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yea, your question is not really clear. From what I understand...

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.

rockym

11:32 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



Thanks for the reply, let me clear this up a bit.
My function is generating this little query to send to the database (strSearch is what the user types into the webform):

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.

rockym

12:34 am on Jan 27, 2004 (gmt 0)

10+ Year Member



Ok, i solved my own problem. :)
I was having a brain-fart!
I didn't realize that VB handles arrays as arrValues(x) and was trying to use the old arrVal[x] from C.
<sigh>
Anyhow, i got my problem fixed.
Thanks again for having this forum for me to post my silly question to.