【问题标题】:Access DB Table - Split Field SQL CommandAccess DB 表 - 拆分字段 SQL 命令
【发布时间】:2014-04-15 04:21:59
【问题描述】:

我有一个 Access 2013 数据库表,dbo_GOV

目标

我想获取包含如下数据的 USSenator 字段,并将其分别拆分为 USSenator1 和 USSenator2 字段:

John Smith;Sarah Levens
Bill Burr;Kevin Nill
George Thomson;Tracy Johnson

问题

我尝试了几个不同的 Access SQL 查询...都(如下)在执行时给出错误消息

“.”、“!”或“()”的使用无效。在查询表达式中 'Split(USSenators & ";", ';')(0'.

我已验证有 0 条记录,其中 USSenators 为空白。每行列出 2 个人,用分号隔开。


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 文档:here

【问题讨论】:

    标签: sql ms-access split sql-update ms-access-2013


    【解决方案1】:

    您不能在查询中使用 Split,请使用 Mid 和 Instr。

    Mid(USSenators,Instr(USSenators,";")+1)
    Mid(USSenators,1,Instr(USSenators,";")-1)
    

    上面的第 2 行返回 John Smith 的第一条记录
    上面的第 1 行返回 Sarah Levens 的第一条记录

    您需要注意空值。

    【讨论】:

    猜你喜欢
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    • 2014-12-06
    相关资源
    最近更新 更多