【问题标题】:Value from one table as DateAdd interval in INSERT statement to another table一个表中的值作为 INSERT 语句中的 DateAdd 间隔到另一个表
【发布时间】:2018-11-24 16:14:41
【问题描述】:

我需要使用一个表中的值作为 INSERT 语句中的 DateAdd 间隔到第二个表

办公室:

officeID | office | deadline

订单:

orderID | officeID | DateReceived | DateDue

这是我一直在尝试做的事情:

INSERT INTO orders(officeID, DateReceived, DateDue)
    VALUES (1, #2018-06-14#, DateAdd("d", (SELECT deadline FROM offices WHERE officeID = 1), "2018-06-14"))

这可能吗?

感谢任何帮助!

【问题讨论】:

    标签: sql excel vba ms-access insert


    【解决方案1】:

    使用insert . . . select:

    INSERT INTO orders (officeID, DateReceived, DateDue)
       SELECT 1, #2018-06-14#, DateAdd("d", deadline, "2018-06-14")
       FROM offices
       WHERE officeID = 1;
    

    也就是说,我想知道你是否只想要update

    update orders
        set datedue = (select DateAdd("d", deadline, "2018-06-14")
                       from offices
                       where orders.officeID = offices.officeID
                      )
        where officeID = 1;
    

    【讨论】:

    • Insert...Select - 正是我想要的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 2015-04-03
    • 2017-02-17
    • 1970-01-01
    相关资源
    最近更新 更多