|
-
Sep 22nd, 2000, 04:23 PM
#1
Thread Starter
Frenzied Member
Hi,
I'm trying to construct a "wildcard" SQL statement such as:
Code:
Dim sSQL as String
Dim sSearchFor as String
sSearchFor = Text1.Text
sSQL = "SELECT * " _
& "FROM tblTest " _
& "WHERE Field1 LIKE '*" & sSearchFor & "*'"
Set rs = New RecordSet
rs.Open sSQL, db
The idea being that the user can enter any text in Text1 and it will find any record where Field1 contains the text that the user entered..
But, it does not seem to be returning any records. It does not seem to like the wildcards.. It doesn't error out, but it just doesn't return any records... And yes, I have verified that the text does in fact exist in the database.. When I remove the * signs, then the records are returned, if I enter the whole Field1 text..
Any idea on how to make this thing work?
Thanks,
Dan
-
Sep 22nd, 2000, 04:36 PM
#2
try this:
Code:
Dim sSQL as String
Dim sSearchFor as String
sSearchFor = Text1.Text
sSQL = "SELECT * FROM tblTest " _
& "WHERE Field1 LIKE '%" & sSearchFor & "%'"
Set rs = New RecordSet
rs.Open sSQL, db
cause when using LIKE in SQL, the % sign that comes in front of or behind (a) letter(s) stands for the wildcard.
-
Sep 22nd, 2000, 04:55 PM
#3
Thread Starter
Frenzied Member
Thank you, that worked!!!
Dan
-
Sep 22nd, 2000, 05:09 PM
#4
no prob. glad to have helped.
-
Sep 22nd, 2000, 07:09 PM
#5
Frenzied Member
It's going to depend on the DBMS and what you use to access it. Microsoft Access (with DAO) will use the "*" in place of the "%"
-
Sep 23rd, 2000, 12:36 AM
#6
Lively Member
More information
I have used a "*" for query like that and it works fine for me. I use ADO and SQL Server 7.0.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|