2

下面的 SQL 代码有什么问题:

INSERT INTO tbl_HAMP_Actions ( Loan_ID, Action_ID, Event_User, Event_Time, Event_Station, Reason_ID )
VALUES(3238, 3, 'CONTROL', Now(), 'CONTROL', (SELECT tbl_Reasons.Reason_ID
FROM tbl_Reasons
WHERE tbl_Reasons.Reason = 'Incorrect Information'));
4

3 回答 3

0

我认为您不能将子查询用作 Access 中的值。试试这个:

INSERT INTO tbl_HAMP_Actions ( Loan_ID, Action_ID, Event_User, Event_Time, Event_Station, Reason_ID )
SELECT 3238, 3, 'CONTROL', Now(), 'CONTROL', Reason_ID
FROM tbl_Reasons
WHERE tbl_Reasons.Reason = 'Incorrect Information'
于 2013-10-24T21:49:56.563 回答
0
    (SELECT tbl_Reasons.Reason_ID
FROM tbl_Reasons
WHERE tbl_Reasons.Reason = 'Incorrect Information')

这部分代码可以返回多行吗?如果是这样,那么这将失败。

于 2013-10-24T21:50:09.063 回答
0

我认为您可能会通过如下所示的查询获得更好的运气:

INSERT INTO tbl_HAMP_Actions 
    (
        Loan_ID, 
        Action_ID, 
        Event_User, 
        Event_Time, 
        Event_Station, 
        Reason_ID 
    ) VALUES (
        3238, 
        3, 
        'CONTROL', 
        Now(), 
        'CONTROL', 
        DLookup("Reason_ID","tbl_Reasons","Reason = 'Incorrect Information'")
    )
于 2013-10-24T21:51:50.123 回答