Avatar of jodstrr2
jodstrr2
 asked on

Show only First letter of first name and full last Name

Hi Experts,
How do I get the first letter of first name and full last name in query?
example,
Jane.Doe
I want to get is only JDoe.  

I only get to is the first letter is
Name: Left([UserName],1) this gave me the first letter of first name.

Thanks
Microsoft Access

Avatar of undefined
Last Comment
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

8/22/2022 - Mon
sjklein42

Try this:

LEFT([UserName],1) + SUBSTRING([UserName], CHARINDEX('.', [UserName])+1, 999)

Open in new window

Bill Ross

Hi,

If the format of the name is Jan.Doe you need to put 2 parts together.

First initial of First Name = Left([Name],1)

Last Name is a bit more tedious.  You need to find the position of the period and get everything after that.
Instr([Name],".") will return the position of the "."
Len([Name]) will return the length of the string.
Last Name then can be computed by Right(Instr([Name],".")+1,Len([Name])-Instr([Name],"."))
Combine the 2 expressions:

Name Like You want =  Left([Name],1) & Right(Instr([Name],".")+1,Len([Name])-Instr([Name],"."))

Regards,

Bill
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

Example:

Left("Jon Dough",1) & Mid("Jon Dough",  InStrRev("Jon Dough"," ")+1)
Returns
JDough
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Bill Ross

S/B
Name Like You want =  Left([UserName],1) & Right(Instr([UserName],".")+1,Len([UserName])-Instr([UserName],"."))

Bill
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

So ... generic:

Left(YourName,1) & Mid(YourName,  InStrRev(YourName," ")+1)
JDough
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

SELECT query:

SELECT Left([FullName],1) & Mid([FullName],InStrRev([FullName]," ")+1) AS NewName
FROM Table1
WHERE (((Table1.FullName) Is Not Null));
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jodstrr2

ASKER
I tried
1). sjklein42's soultion, I got the error message "Undefined function "Substring" in expression" and undefined function "CHARINDEX" in expression"

2).BillDenver's, I got the result is first Letter of first name and numbers.  for example, the result is A7, A10 etc.

3). DatabaseMX's, I got the New name as Jane.Doe
ASKER CERTIFIED SOLUTION
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

SELECT query:

SELECT Left([FullName],1) & Mid([FullName],InStrRev([FullName],".")+1) AS NewName
FROM Table1
WHERE (((Table1.FullName) Is Not Null));
jodstrr2

ASKER
Works great, thanks!!!!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

Sorry for the confusion.  I swear ... I saw a Space instead of a period :-)

mx