Isaac
Isaac

Reputation: 351

SQL INSERT: Column name or number of supplied values does not match table definition

I can't figure out even after reading other questions that have a similar title, why this isn't working. I get an error on the final INSERT statement.

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

I checked, and PENDS_BAA_MASTER_Temp definitely has columns UserAssigned, DateAssignedToAnalyst, AssignmentStatus, DateImportedFromSQL, DateCompletedByBAA, DateSentToClaimsToolbar. And they are the exact same column types as PENDS_BAA_MASTER, which, due to the flow of my statements, should carry through.

Upvotes: 0

Views: 121

Answers (1)

Sean Lange
Sean Lange

Reputation: 33581

I would do this as a single insert statement. Like this. You have FormNbr in your original query but didn't mention it in the target table.

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

Upvotes: 1

Related Questions