Results 1 to 4 of 4
  1. #1
    frksdf is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    12

    [SOLVED] WHERE statement in lookup coloumn

    I have an İssue about using SQL statments with a table in which there is look-up column.
    Code:
     
    SELECT Supp_Name,Supp_Company FROM Supplier WHERE Supp_Name="ATK"
    This code working very well. It retrieves Supplier names and Supplier Company names that supplier names are ATK.
    But;
    Code:
     
    SELECT Supp_Name,Supp_Company FROM Supplier WHERE Supp_Company="ATK"
    If I run this code; I got the error message that states "Data type mismatch in criteria expression".

    By the way; Supp_Company field is a look-up coloumn that retrieves the data from Comp_name field in Company table.



    Is it impossibe to use lookup-coloums in WHERE statement ?
    (Access 2007 sql query - not SQL server)
    Thanks for your help and interest ?

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    What you describe is a typical problem associated with having lookups at the table level. Even though Access has this capability, it is generally recommended to not have lookups in your tables. This site explains the issues in more detail.

    The best approach is to spin off the lookup items (whatever they are) into their own table and just reference the key field in the primary table. For example, let's say you have a table of addresses with a lookup field for state names. You would separate the state names into their own table...

    tblStates
    -pkStateID primary key, autonumber
    -txtStateName

    Then in your address table just reference the pkStateID field as a foreign key

    tblAddresses
    -pkAddID primary key, autonumber
    -txtStreetAddress
    -txtCity
    -fkStateID foreign key to tblStates

    In a query you would bring in both tables and join them via the pkStateID-fkStateID. You can then select either of the ID fields or the name of the state depending on what you need.

  3. #3
    frksdf is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Thank you very much jzwp11;

    Your answer has lots of valuable information.

    Regards,,,

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to mark a thread as solved
    By Matrix in forum Forum Suggestions
    Replies: 10
    Last Post: 12-12-2019, 06:55 AM
  2. Replies: 1
    Last Post: 07-22-2010, 05:52 PM
  3. Replies: 0
    Last Post: 03-15-2009, 03:22 AM
  4. Any function regarding remainder??? [Solved]
    By wasim_sono in forum Forms
    Replies: 2
    Last Post: 10-21-2006, 01:53 AM
  5. How to use array? [ solved] Thanks.
    By wasim_sono in forum Programming
    Replies: 0
    Last Post: 10-20-2006, 12:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums