Results 1 to 5 of 5

Thread: SQL - "LIKE" statement

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Post

    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
    [email protected]
    http://omarswan.da.ru/

    "Jesus is Lord"

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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

  3. #3
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    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
    [email protected]

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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

  5. #5
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    Clunietp,

    You are absolutely right!

    Ruchi

    [This message has been edited by Ruchi (edited 12-28-1999).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width