|
-
Jul 11th, 2000, 05:57 PM
#1
Thread Starter
New Member
I am trying to search a database in a not exact manner and know that I can use the like statement to help with this search of the database but do not know exactally how to do this. Any help?
-
Jul 11th, 2000, 06:05 PM
#2
Fanatic Member
Try:
SELECT * FROM TABLE_NAME WHERE COLUMN_NAME LIKE '*CRITERIA*'
TABLE_NAME is name of the table that you want to extract the data. Insert your table name here.
COLUMN_NAME is the name of the column. Insert your column name here.
* is a wild card character CRITERIA is the data you want and another * wildcard at the end.
For example: Say my table is named CONTACTS and the column is called NAME(contains first and last separated by a space) then I would use:
SELECT * FROM CONTACTS WHERE NAME LIKE 'John*'
This will return all names beginning with John, the last name is the wildcard.
Psyrus
-
Jul 11th, 2000, 06:15 PM
#3
Hyperactive Member
The wildcards depend on what Database you are running the Query on.
If you are using SQL Server then the wildcards are :
% - (Percent) Match none or more characters
_ - (Underscore) Match EXACTLY one character
LIKE '%ed' will find : (ends in)
fred
bed
LIKE '%ed%' will find : (contains)
fred
bed
medical
LIKE '_ed' will find : (3 letter word, any 1st letter)
bed
ted
wed
-
Jul 11th, 2000, 06:18 PM
#4
Or you could use something like
Code:
sName = "John"
rs.movefirst
Do
rs.FindNext("Name Like '*" & sName & "*'")
If rs.EOF Then
MsgBox "Damn got that one Wrong"
Exit Do
End If
'
' Is this the record you want sort of testing
'
Exit Do
Loop
...or something similar. Psyrus answer is good if you want to extract all records from a Table which match a criteria for processing. The above code is good if you are seeking a single instance.
Hope this Helps
-
Jul 13th, 2000, 08:10 AM
#5
Thread Starter
New Member
Thanks
Thanks for your help Psyrus, Gen-X, and Jethro. I went with the approach Gen X submitted. I forgot to mention that it was a SQL database. Hope I am able to get the same levle of quality responses in the future.
Nixoid
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
|