Msg 213,Level 16,State 1,Line 1

时间:2013-05-07 21:00:21

标签: sql-server-2008

INSERT INTO AuditRecord 
    (AuditActionId
    ,EntityName
    ,EntityKey
    ,CreateUser
    ,CreateDate)
OUTPUT inserted.AuditRecordId INTO #InsertedArEmailAndStatus 
SELECT 
    2 /* update */
    ,'CustomerContact'
    ,ContactId
    ,CURRENT_USER
    ,CURRENT_TIMESTAMP
FROM #UpdatedEmailAndStatus
#InsertedArEmailAndStatus中的

有3列。 在#UpdatedEmailAndStatus中有4列,但在AuditRecord我插入了5列,那么我在哪里添加第5列?是#InsertedArEmailAndStatus还是#UpdatedEmailAndStatus

1 个答案:

答案 0 :(得分:2)

您的实际问题是您没有将足够的值传递给#InsertedArEmailAndStatus尝试此操作(将col2,col3替换为您要存储在EmailAndStatus表中的列)

INSERT INTO AuditRecord 
    (AuditActionId
    ,EntityName
    ,EntityKey
    ,CreateUser
    ,CreateDate)
OUTPUT inserted.AuditRecordId, Inserted.Col2, Inserted.col3 
INTO #InsertedArEmailAndStatus 
SELECT 
    2 /* update */
    ,'CustomerContact'
    ,ContactId
    ,CURRENT_USER
    ,CURRENT_TIMESTAMP
FROM #UpdatedEmailAndStatus