Here is the code and yes it is a response write result that shows this on the top of my web page... it's complicated for sure, but I am trying to build a "fuzzy" seach on the last name, so that they can use the like command as well as the exact equals on the WHERE clause...
strQuery = "SELECT * FROM people WHERE "
if strPrefix = "ON" OR strSuffix = "ON" then
strStar = "*"
strOperator = " like "
else
strOperator = "="
strStar = ""
End if
if strLastName <> "" then
if strPrefix = "ON" then
if strSuffix = "ON" then
QueryAdd1 = "last_name " & strOperator & "'" & strStar & strLastName & strStar & "'"
else
QueryAdd1 = "last_name " & strOperator & "'" & strLastName & strStar & "'"
end if
else
QueryAdd1 = "last_name " & strOperator & " '" & strLastName & "'"
end if
strQuery = strQuery & QueryAdd1
if strFirstName <> "" then
QueryAdd2 = " AND first_name = '" & strFirstName & "'"
strQuery = strQuery & QueryAdd2
end if
Else
if strFirstName <> "" then
QueryAdd2 = "first_name = '" & strFirstName & "'"
strQuery = strQuery & QueryAdd2
end if
end if
are you querying against SQL Server, or is it MS Access? the "like" wildcard for SQL is actually %, instead of *.
also - if you want to do a little more efficient search, do the following:
SELECT * FROM people WHERE last_name like 'mac*'
lastnamevariable = "mac"
sqlstring = "SELECT * FROM people WHERE left(last_name, "
sqlstring = sqlstring & cstr(len(lastnamevariable))
sqlstring = sqlstring & " = 'mac'"
will output the following:
SELECT * FROM people WHERE left(last_name, 3) = 'mac'
This will work in SQL Server, and SHOULD work in access, but truthfully, I haven't tried it. I've been told that left(fieldname) searches will be faster than a "like" because of how it searches the data.
Since you're eventually moving to SQL 7, I strongly suggest that you develop on MSDE and not MS Access. As you've seen, the SQL is slightly different in Access. If you were to use MSDE, not only is the SQL the same, but the database files themselves use the same format as SQL 7. You could do a simple file copy from your development box to your production box.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.