|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Wildcards not matching in vbscript ASP called query
I'm sure this is a basic problem, i'm v. rusty at SQL these days, and i've had no luck on google, as all the suggestions seem to point that my query is correct.
Sample code below (which has the working query and the non-working query) does not return the same thing, when each is commented out. i.e. the search returns Belgium if a direct match is provided, but Bel* does not return it. What am i doing wrong? thanks for any advice cheers Ben sample code Set conn_CountryPhoneInfo = Server.CreateObject("ADODB.Connection") Set rs_CountryPhoneInfo = Server.CreateObject("ADODB.Recordset") DSNStatement = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" DSNStatement = DSNStatement & Server.MapPath(db_CheepDialDB) conn_CountryPhoneInfo.Open DSNStatement rs_CountryPhoneInfo.CursorType = 0 rs_CountryPhoneInfo.CursorLocation = 2 Elseif HowPageIsUsed = "SearchCountry" Then ' we will do 2 things ' 1. search based on the 'entire string' ' 2. if nothing is returned, search based on the components of the string and present the options SQLStatement = "SELECT * FROM CountryList WHERE Country LIKE" & chr(39) & countryname & chr(39) End If ' To test use the following query ' http://localhost/cd_7/Countries.asp?How=SearchCountry&SearchTerms=Af if (HowPageIsUsed ="SearchCountry") Then rs_CountryPhoneInfo.Open SQLStatement, conn_CountryPhoneInfo, 3, 3 IF rs_CountryPhoneInfo.EOF THEN ' Can't find the immediate country, so split up by the spaces and search for each term ORing rs_CountryPhoneInfo.Close ' This statement does work (if uncommented) ' SQLStatement = "SELECT * FROM CountryList WHERE Country LIKE 'Belgium'" ' THIS statement does not work - and should return the same value as the one above SQLStatement = "SELECT * FROM CountryList WHERE Country LIKE '*Bel*'" rs_CountryPhoneInfo.Open SQLStatement, conn_CountryPhoneInfo, 3, 3 IF rs_CountryPhoneInfo.EOF THEN DebugString 1, "And again, Search Country NOT found" else DebugString 1, "And again, Search found something" end if End if End if |
|
#2
|
||||
|
||||
|
wildcard for SQL is '%'
|
|
#3
|
||||
|
||||
|
Yes I was going to suggest that the wildcard(%) be inserted. Also to refer to your code:
Code:
SQLStatement = "SELECT * FROM CountryList WHERE Country LIKE" & chr(39) & countryname & chr(39) You might also try something like this... Code:
SQLStatement = "SELECT * FROM CountryList WHERE Country LIKE" & chr(39) & "'" & "(%" & countryname & "%)" & "'" & chr(39) I am not able to test that here, but I do hope that helps! |
|
#4
|
|||
|
|||
|
Doh! thanks - all the information i didn't notice * versus %!
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Wildcards not matching in vbscript ASP called query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|