Access DB 表 - 拆分字段 SQL 命令 [英] Access DB Table - Split Field SQL Command
问题描述
我有一个 Access 2013 数据库表,dbo_GOV
I have an Access 2013 Database Table, dbo_GOV
目标
我想获取包含如下数据的 USSenator 字段,并将其分别拆分为 USSenator1 和 USSenator2 字段:
I want to take the USSenators field, which contains data like (below) and split it into USSenator1 and USSenator2 fields, respectively:
John Smith;Sarah Levens
Bill Burr;Kevin Nill
George Thomson;Tracy Johnson
<小时>
问题
我尝试了几个不同的 Access SQL 查询...都(如下)在执行时给出错误消息
I've tried a few different Access SQL queries... both (below) when executed, give the error message
."、!"或()"的使用无效.在查询表达式中'Split(USSenators & ";", ';')(0'.
Invalid use of '.', '!', or '()'. in query expression 'Split(USSenators & ";", ';')(0'.
我已验证有 0 条记录,其中 USSenators 为空白.每行列出 2 个人,用分号隔开.
I have verified that there are 0 records, where USSenators is blank. Every row has 2 people listed, separated by a semicolon.
SQL 查询
UPDATE dbo_GOV
SET
USSenator1 = Split(USSenators & ";",';')(0),
USSenator2 = Split(USSenators & ";",';')(1);
<小时>
UPDATE dbo_GOV
SET
USSenator1 = Split(USSenators,';')(0),
USSenator2 = Split(USSenators,';')(1);
<小时>
我已尝试参考拆分的 Office 文档:这里
推荐答案
你不能在查询中使用 Split,使用 Mid 和 Instr.
You cannot use Split in a query, use Mid and Instr.
Mid(USSenators,Instr(USSenators,";")+1)
Mid(USSenators,1,Instr(USSenators,";")-1)
上面的第 2 行返回 John Smith 的第一条记录
上面的第 1 行返回 Sarah Levens 的第一条记录
Line 2 above returns John Smith for the first record
Line 1 above returns Sarah Levens for the first record
您需要注意空值.
这篇关于Access DB 表 - 拆分字段 SQL 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!