如何在执行更新时使用输出 inserted.* into table 变量
how to use output inserted.* into table variable while doing Update
我第一次尝试插入输出,但无法理解错误消息:
Insert Error: Column name or number of supplied values does not match table definition.
目标:我有很多账户的巨额索赔table。我想在几个帐户中将值更新为 1 并能够显示更新。
所以,我用我要更新的帐户创建了一个@TEMP_tbl
*/
DECLARE @TEMP_tbl TABLE(
SORIGCREDITORREFNO VARCHAR(30),
BCLAIMONHOLD INT)
INSERT INTO @TEMP_tbl (SORIGCREDITORREFNO,BCLAIMONHOLD)
VALUES ('1234',0)
-- writing my update statement
DECLARE @MYVAR TABLE ( SORIGCREDITORREFNO VARCHAR(30),BCLAIMONHOLD INT)
UPDATE CLAIM
SET BCLAIMONHOLD = 1
OUTPUT INSERTED.* INTO @MYVAR
WHERE SORIGCREDITORREFNO IN (SELECT SORIGCREDITORREFNO FROM @TEMP_tbl)
SELECT * FROM @MYVAR
-- want to look at my updates
Msg 213, Level 16, State 1, Line 16 Insert Error: Column name or
number of supplied values does not match table definition.
您需要将 * 替换为字段名称
UPDATE CLAIM
SET BCLAIMONHOLD = 1
OUTPUT INSERTED.SORIGCREDITORREFNO , INSERTED.BCLAIMONHOLD INTO @MYVAR
WHERE SORIGCREDITORREFNO IN (SELECT SORIGCREDITORREFNO FROM @TEMP_tbl)
当您指定 * 时,表示来自 CLAIM table 的所有字段,与@MYVAR 变量
中的字段不匹配
我第一次尝试插入输出,但无法理解错误消息:
Insert Error: Column name or number of supplied values does not match table definition.
目标:我有很多账户的巨额索赔table。我想在几个帐户中将值更新为 1 并能够显示更新。
所以,我用我要更新的帐户创建了一个@TEMP_tbl */
DECLARE @TEMP_tbl TABLE(
SORIGCREDITORREFNO VARCHAR(30),
BCLAIMONHOLD INT)
INSERT INTO @TEMP_tbl (SORIGCREDITORREFNO,BCLAIMONHOLD)
VALUES ('1234',0)
-- writing my update statement
DECLARE @MYVAR TABLE ( SORIGCREDITORREFNO VARCHAR(30),BCLAIMONHOLD INT)
UPDATE CLAIM
SET BCLAIMONHOLD = 1
OUTPUT INSERTED.* INTO @MYVAR
WHERE SORIGCREDITORREFNO IN (SELECT SORIGCREDITORREFNO FROM @TEMP_tbl)
SELECT * FROM @MYVAR
-- want to look at my updates
Msg 213, Level 16, State 1, Line 16 Insert Error: Column name or number of supplied values does not match table definition.
您需要将 * 替换为字段名称
UPDATE CLAIM
SET BCLAIMONHOLD = 1
OUTPUT INSERTED.SORIGCREDITORREFNO , INSERTED.BCLAIMONHOLD INTO @MYVAR
WHERE SORIGCREDITORREFNO IN (SELECT SORIGCREDITORREFNO FROM @TEMP_tbl)
当您指定 * 时,表示来自 CLAIM table 的所有字段,与@MYVAR 变量
中的字段不匹配