在访问查询中拆分姓氏和中间名

问题描述 投票:0回答:1

我有全名字段,我想拆分并从名称中删除中间名。

名称类似:

[史密斯,詹姆斯D->结果是:史密斯,詹姆斯

[Doe,John Snow->结果是:Doe,John

这是我所做的,但不确定删除中间名会丢失什么

FName: Mid([Employee] & "",InStr(1,[Employee] & " ",",")+1)
Lname: Left([Employee] & "",InStr(1,[Employee] & "",",")+(InStr(1,[Employee] & "",",")>0))  

Smith,James D->我知道-> FName:James D

Doe,John Snow->我知道-> FName:John Snow

sql ms-access ms-access-2010 access
1个回答
0
投票

假设每个名称总会有3个部分,而第3个部分是中间名/首字母,并且逗号后没有空格,请考虑:

LastFirst: Left([Employee], InStrRev([Employee]," ")-1

Last: Left([Employee], InStr([Employee],",")+1)

First: Mid(Left([Employee],InstrRev([Employee]," ")-1),Instr([Employee],",")+1)

Middle: Mid([Employee], InStrRev([Employee], " ")+1)

© www.soinside.com 2019 - 2024. All rights reserved.