Results 1 to 5 of 5
  1. #1
    MiaAccess is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31

    Parsing by using a delimiter in a query

    I working with payroll. I have codes like L1-Hrl but also some with just one letter like G-Hrl. I need to extract just what is before the dash resulting of L1 and G.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use the Left() function along with the InStr() function to find the position of the dash.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    MiaAccess is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31
    Got it:
    Lettercode: Left([payrollitem],(Instr(1,[payrollitem],"-")-1))
    This give me the correct answer.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Just for info, you can also do this using the Split function e.g. Split("l1-grl", "-")(0)
    Unfortunately this can't be used directly in a query but a workaround is to use the String_Split function which can be used in queries
    See https://www.devhut.net/2018/04/22/ac...it-in-a-query/

    Using this approach your query field becomes
    Code:
    String_Split([payrollitem],0,"-")
    You might find this approach easier in future
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by MiaAccess View Post
    Got it:
    Lettercode: Left([payrollitem],(Instr(1,[payrollitem],"-")-1))
    This give me the correct answer.
    Glad it worked for you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Special Delimiter characters
    By cliff.clayman in forum Import/Export Data
    Replies: 12
    Last Post: 09-13-2016, 10:52 AM
  2. Delimiter expressions
    By kjcochran in forum Queries
    Replies: 3
    Last Post: 06-16-2013, 06:45 AM
  3. Using double quote as text delimiter
    By EddieN1 in forum SQL Server
    Replies: 4
    Last Post: 03-11-2012, 08:49 PM
  4. Using pound sign as date delimiter
    By EddieN1 in forum SQL Server
    Replies: 1
    Last Post: 03-07-2012, 10:38 PM
  5. Replies: 0
    Last Post: 10-06-2010, 11:56 AM

Tags for this Thread

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