Splitting a field in a query

W

Wendy

Hi All

I have a name field in my query with Smith, John Charles. I need to know
how to split it on the comma and spaces so I get 3 fields Smith John
Charles. I receive the data in this format so cannot change it at source.
Can someone point me in the right direction please?

Thanks in advance

Wendy
 
L

Lynn Trapp

Wendy,
Working on the assumption that your names all come in the format of
"LastName, FirstName MiddleName", the following should work for you. It's a
bit long winded, but you ought to be able to just copy and paste it into the
sql view of a new query -- taking care to change the field name and table
name appropriately.

SELECT Left([nametest],InStr([nametest],',')-1) AS LastName,
Left(Mid([nametest],InStr([nametest],',')+2),InStr(Mid([nametest],InStr([nam
etest],',')+2),' ')) AS FirstName,
Mid(Mid([nametest],InStr([nametest],',')+2),Len(Left(Mid([nametest],InStr([n
ametest],',')+2),InStr(Mid([nametest],InStr([nametest],',')+2),' ')))+1) AS
MiddleName
FROM NamesTest;
 
W

Wendy

Thanks Lynn it works fine
Wendy said:
Hi All

I have a name field in my query with Smith, John Charles. I need to know
how to split it on the comma and spaces so I get 3 fields Smith John
Charles. I receive the data in this format so cannot change it at source.
Can someone point me in the right direction please?

Thanks in advance

Wendy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top