代码之家  ›  专栏  ›  技术社区  ›  sigil

“)”附近的语法不正确,是否可能错误使用了substring()或charindex()?

  •  0
  • sigil  · 技术社区  · 13 年前

    我正试图使用以下字符串定义的查询,在ProjectWise的SQL Server数据库实例上运行ADODB查询:

    select 
    dms_audt.o_acttime as actionTime,
    dms_stat.o_statename as state,
    dms_doc.o_filename as filename,
    dms_doc.o_projectno as project 
    from dms_audt 
    inner join 
    dms_stat 
    on dms_audt.o_numparam2=dms_stat.o_stateno 
    inner join dms_doc on dms_audt.objguid=dms_doc.o_docguid 
    where substring(dms_doc.o_filename,1,4)="abcd") 
    and charindex(dms_doc.o_filename,"efgh")=0
    

    VBA给我的运行时错误为:

    Incorrect syntax near ')'
    

    这让我觉得我要么在用 substring() 或 charindex() 不正确。无论我是否包装 abcd公司 和 efgh公司 单引号或双引号中的字符串。知道我在这里做错了什么吗?

    1 回复  |  直到 13 年前
        1
  •  5
  •   codingbadger    13 年前

    你有一个额外的括号。

    这> where substring(dms_doc.o_filename,1,4)="abcd") and charindex(dms_doc.o_filename,"efgh")=0

    需要:

    where substring(dms_doc.o_filename,1,4)='abcd' and charindex(dms_doc.o_filename,'efgh')=0