SQL INSERT:列名或提供的值数与表定义不匹配

时间:2014-09-03 17:02:04

标签: sql sql-server tsql select

即使在阅读了具有相似标题的其他问题后,我也想不通,为什么这不起作用。我在最后的INSERT语句中收到错误。

WITH qryRecordsNotYetCompleted AS
(
    SELECT  FormNbr,
            UserAssigned,
            DateAssignedToAnalyst,
            AssignmentStatus,
            DateImportedFromSQL,
            DateCompletedbyBAA,
            DateSentToClaimsToolbar
    FROM PENDS_BAA_MASTER WHERE ISNULL(DateCompletedbyBAA,'')=''
)
--/**********************************************************************************************

--2) For all those records, save any ASSIGNMENT information AND original DateImportedFromSQL value
SELECT qryRecordsNotYetCompleted.* INTO #TempPends FROM qryRecordsNotYetCompleted

--/**********************************************************************************************

--2b:
INSERT PENDS_BAA_MASTER_Temp
SELECT * FROM #TempPends

我检查过,PENDS_BAA_MASTER_Temp肯定有UserAssigned,DateAssignedToAnalyst,AssignmentStatus,DateImportedFromSQL,DateCompletedByBAA,DateSentToClaimsToolbar列。它们与PENDS_BAA_MASTER完全相同的列类型,由于我的陈述流程,它应该贯彻执行。

1 个答案:

答案 0 :(得分:1)

我会将此作为单个插入语句执行。像这样。您在原始查询中有FormNbr,但未在目标表中提及它。

INSERT PENDS_BAA_MASTER_Temp
(
    UserAssigned
    , DateAssignedToAnalyst
    , AssignmentStatus
    , DateImportedFromSQL
    , DateCompletedbyBAA
    , DateSentToClaimsToolbar
)
SELECT UserAssigned
    , DateAssignedToAnalyst
    , AssignmentStatus
    , DateImportedFromSQL
    , DateCompletedbyBAA
    , DateSentToClaimsToolbar
FROM PENDS_BAA_MASTER