Click to See Complete Forum and Search --> : SQL - "LIKE" statement
omarswan
Dec 22nd, 1999, 09:53 AM
On a form I have a textbox called "FirstName". If a user enters the letter "A". How would I create an SQL statement that would list all the recods that begin with the letter "A"
------------------
OmarSwan
Student
omarswan@yahoo.com
http://omarswan.da.ru/
"Jesus is Lord"
Clunietp
Dec 22nd, 1999, 10:33 AM
If you are using an MS Access database:
Select * from MyTable where FirstName LIKE 'A*'
or with a VB textbox
Select * from MyTable where FirstName LIKE '" & text1.text & "*'"
If you are not using Access, and are using a different DB (like SQL Server) use a percent sign at the end of your like parameter instead of an asterisk
Select * from MyTable where FirstName LIKE 'A%'
Tom
Ruchi
Dec 24th, 1999, 03:59 AM
These two predicates are used for matching strings simliar to the equal (=) conditional. The two wild characters used with SQL are .
% - matches any string
* - matches any character
i.e.
Assume that we want to find all the FirstName in the database, but are not sure of the spelling used. The 'A' can be used with the % wildcard for the search.
Do what Clunietp uses.
Select * from MyTable where FirstName LIKE 'A*'
Select * from MyTable where FirstName LIKE '" & Text1.Text & "*'"
Select * from MyTable where FirstName LIKE 'A%'
------------------
Ruchi
ruchivb@yahoo.com
Clunietp
Dec 24th, 1999, 01:34 PM
Ruchi
* does not match a single character, in Jet-SQL, the ? (question mark) is the placeholder for the single character. The * in jet sql matches any string length (zero or more)
The % (percent sign) in T-SQL (SQL Server) acts as the same as the * in jet SQL, while the _ (underscore) acts as the ? (question mark) in Jet-SQl, being the single character placeholder
I'm not sure if you meant it this way, but I got a little confused on what you were trying to say, and wanted to clarify
Thanks
Tom
Ruchi
Dec 27th, 1999, 12:52 PM
Clunietp,
You are absolutely right!
Ruchi
[This message has been edited by Ruchi (edited 12-28-1999).]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.