检查表中的字段是否有空格或逗号 - MS-Access
我有一个名为 FinalForgotten 的表,其中仅包含一个名为 aname 的字段。该字段可以看起来像 Smith John 或 Smith,John。因此姓氏和名字都在同一字段中,并以空格或逗号分隔。防御字段包含三个字段:first_name、last_name、middle_initial。 first_name 字段将包含与name 字段中的数据完全匹配的数据(例如John)。并且last_name 字段将包含与aname 字段中的一条数据完全匹配的数据(例如Smith)。我试图将所有带有中间首字母的 FinalForgotten 名称记录放入新表中(例如 Smith,John S)。防御表就是有这个中间首字母的。
这可行:
SELECT left([aname],InStr(1,[aname],",")-1) & " "& right([aname],Len(aname)-InStr(1,[aname],",")) & " "& summary_judgment.middle_initial AS fullnameINTO FinalForgottenWithMiddle FROM FinalForgotten INNER JOIN summary_judgment ON((left(FinalForgotten.aname,InStr(1,FinalForgotten.[aname],",")-1))=summary_judgment.last_name) AND((right(FinalForgotten.aname,Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))=summary_judgment.first_name));
但如果 FinalForgotten 包含一个没有逗号的字段,它将返回“无效的过程调用”,例如: 史密斯·约翰.
因此,为了解决这个问题,我尝试考虑字段中是否有逗号:
SELECT left([aname], IIF(instr([aname], ",") = 0, InStr(1,[aname]," ")-1),InStr(1,[aname],",")-1) & ", " & right([aname], IIF(instr([aname], ",") = 0,Len(aname)-InStr(1,[aname]," "),Len(aname)-InStr(1,[aname],",") & " " & defense_final.middle_initial AS fullname INTO FinalForgottenWithMiddle
FROM FinalForgotten INNER JOIN defense_final ON
((right(FinalForgotten.aname,IIF(instr([aname], ",") = 0,Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," ")),Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))=defense_final.first_name))
AND
((left(FinalForgotten.aname,,IIF(instr([aname], ",") = 0,InStr(1,FinalForgotten.[aname]," ")-1)),InStr(1,FinalForgotten.[aname],",")-1))=defense_final.last_name);
这给了我一个“缺少运算符语法”错误并突出显示了单词 AS。
感谢您的回复。
I have table called FinalForgotten which only contains one field called aname. The field could either look like Smith John or Smith,John. So both last and first name are in same field and delimited by either space or comma. The defense field contains three fields: first_name,last_name,middle_initial. The first_name field will contain data that matches exactly a piece a data IN aname field (e.g. John). And the last_name field will contain data that matches exactly a piece of data IN aname field (e.g. Smith). I'm trying to get all the FinalForgotten aname records with a middle initial into a new table (e.g. Smith,John S). The defense table is what has this middle initial.
This would work:
SELECT left([aname],InStr(1,[aname],",")-1) & " "& right([aname],Len(aname)-InStr(1,[aname],",")) & " "& summary_judgment.middle_initial AS fullnameINTO FinalForgottenWithMiddle FROM FinalForgotten INNER JOIN summary_judgment ON((left(FinalForgotten.aname,InStr(1,FinalForgotten.[aname],",")-1))=summary_judgment.last_name) AND((right(FinalForgotten.aname,Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))=summary_judgment.first_name));
But it will return "invalid procedure call" should FinalForgotten contain a field that doesn't have a comma like:
Smith John.
Hence, to address this, I tried to factor whether a comma was in the field or not:
SELECT left([aname], IIF(instr([aname], ",") = 0, InStr(1,[aname]," ")-1),InStr(1,[aname],",")-1) & ", " & right([aname], IIF(instr([aname], ",") = 0,Len(aname)-InStr(1,[aname]," "),Len(aname)-InStr(1,[aname],",") & " " & defense_final.middle_initial AS fullname INTO FinalForgottenWithMiddle
FROM FinalForgotten INNER JOIN defense_final ON
((right(FinalForgotten.aname,IIF(instr([aname], ",") = 0,Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," ")),Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))=defense_final.first_name))
AND
((left(FinalForgotten.aname,,IIF(instr([aname], ",") = 0,InStr(1,FinalForgotten.[aname]," ")-1)),InStr(1,FinalForgotten.[aname],",")-1))=defense_final.last_name);
This gives me a "missing operator syntax" error and highlights the word AS.
Thanks for response.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
貌似少了好几个括号。
There seems to be quite a few missing parentheses.