Search code examples
ms-accessms-access-2016

MS Access: Take all characters before the second space


I'm working in MS Access. I have a field of names. Some of them have three names (their first, middle, and last). How would I write a query to extract all characters before the second space so that I will be left with just their first and middle name?

If I have a name like John Joe Doe, I just want John Joe portion

Any help would be appreciated. Thank You.

Nick


Solution

  • You can use InStrRev to find the position of the last space and then use Mid to extract the first 2 names. Open the query design and inside one of the field, you can click the expression builder to add InStrRev and Mid functions.

    Assuming that your table has 2 fields, ID and UserName. Open the query designer and add this table. Then add both of the 2 fields to the query and add a third field as NewName. Below is how it should look like on the query design. Hope this is clear. enter image description here