Results 1 to 7 of 7
  1. #1
    DavidZ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2015
    Posts
    9

    How to add * to a field


    Hi All!

    I am trying to return all main and associated job accounts from one table that have a prefix in another. My SQL is as follows:

    SELECT FFFCOMPILE.Customer_ID
    FROM FFFCOMPILE.Customer_ID INNER JOIN MatchingTest ON FFFCOMPILE.Customer_ID LIKE (MatchingTest.Customer_ID & '*')

    Unfortunately, I am only returning rows that are in MatchingTest (that are an exact match with MatchingTest.Customer_ID), but I also want to return rows that have MatchingTest.Customer_ID as a prefix.

    Can anyone tell me why this isn't working?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I think eliminate the JOIN clause, resulting in a Cartesian relationship then use WHERE clause.

    SELECT FFFCOMPILE.Customer_ID FROM FFFCOMPILE.Customer_ID, MatchingTest WHERE FFFCOMPILE.Customer_ID LIKE MatchingTest.Customer_ID & '*'
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  4. #4
    DavidZ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2015
    Posts
    9
    Thanks for your response, June7!

    Just tried this, but unfortunately am still only returning rows that are in MatchingTest. Should I be doing something differently with how I add the wildcard?

  5. #5
    DavidZ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2015
    Posts
    9
    Hi orange,

    You're right. I wrote that incorrectly in the post, but in the query it is FFFCOMPILE.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Post example raw data and example desired output.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    DavidZ is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2015
    Posts
    9
    I know what went wrong.

    Thanks, June7, for having me go back to the basic building blocks. MatchingTest.Customer_ID was not a prefix for associated job accounts, but it was split and "sandwiched" associated job accounts. However, MatchingTest.CustomerName was a prefix, so in the end this worked:

    SELECT DISTINCT FFFCOMPILE.Customer_ID
    FROM FFFCOMPILE INNER JOIN MatchingTest ON FFFCOMPILE.Customer_ID LIKE MatchingTest.CustomerNumber & '*'

    This was my 2nd SQL query ever but I will be doing a lot more moving forward. I will definitely be in this forum to get #educated!

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

Similar Threads

  1. Replies: 17
    Last Post: 03-16-2014, 10:52 PM
  2. Replies: 3
    Last Post: 12-27-2013, 02:33 PM
  3. Replies: 1
    Last Post: 03-03-2012, 10:17 PM

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