Results 1 to 6 of 6

Thread: SQL Question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    29

    Arrow

    I would like to use a wildcard on this search for a user's last name. I know i can use the LIKE command, but i am not sure where to add it. If there is another way to do wildcard search could you please let me know. Thanks

    Altecjjf VB5

    Select * from Customers where ContactLastName = '" & UserInputByLastName & "'"

    Thanks

  2. #2
    Addicted Member JasonGS's Avatar
    Join Date
    May 2000
    Location
    California
    Posts
    155
    "%" is the SQL wildcard, say your looking for MacDonald but you dont know if it was entered as Mac or Mc, you could do %donald%
    Code:
    SELECT * FROM customers WHERE contactlastname LIKE '%" & Text1.Text & "%';"

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb Access vs SQL Server

    I think in Access the wildcard is * but in SQL server is %. If I'm wrong to let me know about it.

    Thanks

  4. #4
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    The wildcard in Access is %.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb Just Found it.

    Thanks Stevie, I just found this from the MSDN.

    Like Operator
    *
    Matches any number of characters, and can be used anywhere in the character string.
    Example:
    wh* finds what, white, and why
    *at finds cat, bat, and what

    ?
    Matches any single character.
    Example:
    b?ll finds ball, bell, and bill

    #
    Matches any single digit.
    Example:
    1#3 finds 103, 113, 123

    [ ]
    Matches any single character within the brackets.
    Example:
    b[ae]ll finds ball and bell but not bill


    !
    Matches any character not in the list.
    Example:
    b[!ae]ll finds bill and bull but not bell or ball


    -
    Matches any one of a range of characters.
    Example:
    b[a-c]d finds bad, bbd, and bcd

    but you also right, because the MSDN also mention about the % wilcard. So may I know what is the diff between the * and % wilcard? and when should use?


    LIKE Operator (T-SQL)
    %
    Any string of zero or more characters.
    Example:
    WHERE title LIKE ¡¥%computer%¡¦ finds all book titles with the word ¡¥computer¡¦
    anywhere in the book title.

    _
    (underscore) Any single character.
    Example:
    WHERE au_fname LIKE ¡¥_ean¡¦ finds all four-letter first names that end with
    ean (Dean, Sean, and so on).

    [ ]
    Any single character within the specified range ([a-f]) or set ([abcdef]).
    Example:
    WHERE au_lname LIKE ¡¥[C-P]arsen¡¦ finds author last names ending with arsen
    and beginning with any single character between C and P, for example Carsen,
    Larsen, Karsen, and so on.

    [^]
    Any single character not within the specified range ([^a-f]) or set ([^abcdef]).
    Example:
    WHERE au_lname LIKE ¡¥de[^l]%¡¦ all author last names beginning with de and where
    the following letter is not l.


    Thanks

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    29

    Cool thank you

    Thank for everybody's help

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