【问题标题】:Compile Error : Syntax Error - MS ACCESS 2007 on SQL INSERT INTO Statement编译错误:语法错误 - SQL INSERT INTO 语句上的 MS ACCESS 2007
【发布时间】:2012-10-20 05:52:38
【问题描述】:

我正在尝试创建以下 SQL INSERT INTO 语句,但出现语法错误。有什么建议吗?:

SQL = "
INSERT INTO AptRent 
    (BuildingID,
     RentAmountID, 
     InitialRentDueDate, 
     TenantID, 
     AptNoID, 
     MoveInDate, 
     MoveOutDate,  
     DateAdded, 
     SecurityAmount, 
     SecurityPaid, 
     NoDaysLate, 
     LateAmount) 
    VALUES
    (" & Me.cbSelectBuildingForRental & "," 
       & Me.cbCreateRentalRentAmount & "," 
       & Me.tbCreateRentalRDD & "," 
       & Me.cbSelectTenantForRental & ", '" 
       & Me.cbSelectAptNoforRental & "' ," 
       & Me.tbCreateRentalMID & "," 
       & Me.tbCreateRentalMOD & "," 
       & Now() & "," 
       & Me.tbSecurityAmnt & "," 
       & Me.ckSecurityPd & "," 
       & Me.tbNoDaysLate & "," 
       & Me.tbLatePmnt & ")"

AptRent 具有以下数据类型:

BuildingRentID:自动编号

BuildingID:编号 (Me.cbSelectBuildingForRental)

RentAmountID:数字(Me.cbCreateRentalRentAmount

InitialRentDueDate:日期/时间(Me.tbCreateRentalRDD

TenantID:编号 (Me.cbSelectTenantForRental)

AptNoID:文本 (Me.cbSelectAptNoforRental)

MoveInDate:日期/时间 (Me.tbCreateRentalMID)

MoveOutDate:日期/时间 (Me.tbCreateRentalMOD)

添加日期:日期/时间(Now()

SecurityAmount:货币 (Me.tbSecurityAmnt)

SecurityPaid:是/否 (Me.ckSecurityPd)

NoDaysLate:数字(Me.tbNoDaysLate

LateAmount: 货币(Me.tbLatePmnt

【问题讨论】:

    标签: ms-access syntax


    【解决方案1】:

    假设它们是 ISO 格式 (YYYY-MM-DD HH:NN:SS),您需要在日期/时间值周围添加单引号。

    ...
    & "'" & Me.tbCreateRentalMID & "', " 
    ...
    

    所有日期/时间列的等等。

    【讨论】:

    • 其实,因为他使用的是ms-access。他会想用#而不是'。
    • @DanielCook:我相信单引号会起作用当值是 ISO 格式时,我在我的假设中说明了这一点。否则,你是对的。
    • 我认为这取决于他使用什么“引擎”来运行此语句。如果它是 DAO 或 ODBC 链接表(也是 DAO),那么他将需要井号。我相信 ADO 也需要哈希符号,尽管我对此并不完全确定。无论如何,他确实需要日期值周围的东西。
    猜你喜欢
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多