Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jul 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SQL in Access (Access 2002)

    I am taking a into to SQL class and I have to create a query using the words BETWEEN and LIKE to restrict record selection. I have 2 tables employees and job title. I would like a query to show the phone numbers in one area code. When I run the query I get no info.
    Here is the query:
    SELECT employee.Phone
    FROM employee
    WHERE (((employee.Phone) Like '858%'))
    ORDER BY employee.Phone;

    What am i doing wrong?
    Thanks
    Rbelly <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: SQL in Access (Access 2002)

    Are you running the query against Access or SQL Server? The % wildcard is SQL Server. Access uses * instead, so it depends on where the SQL is being run.
    Charlotte

  3. #3
    Star Lounger
    Join Date
    Jul 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SQL in Access (Access 2002)

    We are reading SQL but are using Access for this class. I knew there would be problems [img]/forums/images/smilies/smile.gif[/img]
    I changed the % to * and I now get data but I get all the phone numbers and I just want to get the ones that start with 858 How do I do that?

    Thanks for your help.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SQL in Access (Access 2002)

    If you have<pre>WHERE (((employee.Phone) Like '858*'))</pre>

    you should get only the numbers starting with 858. Perhaps *all* phone numbers start with 858 ? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    Star Lounger
    Join Date
    Jul 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SQL in Access (Access 2002)

    I double checked and I only have 3 phone numbers with 858 <img src=/S/smile.gif border=0 alt=smile width=15 height=15> but I changed it to last name Like "S8" and I got the last names that end with S. So that works. I will ask in class why my phone # does not work!

    I am glad I got one to work <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

  6. #6
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: SQL in Access (Access 2002)

    ... to get all of the last names ending with an S you should have put in Like ('*S'). If you used Like ('S8'), it is the same as if you typed ="S8", that is, you should have only received last names of S8.

    In your original clause, try ...phone like ('858*').

    Where are you running the SQL statement? Via query mode or in VB in access?
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

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