【发布时间】:2020-02-07 13:55:14
【问题描述】:
我有以下 SQL Server 游标代码段来插入数据
-- declare a cursor
DECLARE insertapiinvoicedetail_cursor CURSOR FOR
SELECT * FROM Account_APOrderDetail WHERE APOD_Master_Id = @var2;
-- open cursor and fetch first row into variables
OPEN insertapiinvoicedetail_cursor
FETCH NEXT FROM insertapiinvoicedetail_cursor INTO
@Ref_Code,
@Create_UserId,
@Create_Date,
@Modification_UserId,
@Modification_Date,
@CompanyId
-- check for a new row
WHILE @@FETCH_STATUS=0
BEGIN
-- do complex operation here
INSERT INTO Account_APInvoiceDetail
SELECT @Ref_Code,
@Create_UserId,
@Create_Date,
@Modification_UserId,
@Modification_Date,
@CompanyId
-- get next available row into variables
FETCH NEXT FROM insertapiinvoicedetail_cursor INTO @Ref_Code,
@Create_UserId,
@Create_Date,
@Modification_UserId,
@Modification_Date,
@CompanyId
END
close insertapiinvoicedetail_cursor
Deallocate insertapiinvoicedetail_cursor
GO
但我在这里收到以下错误消息
'Msg 213, Level 16, State 1, Line 128
列名或提供的值的数量与表定义不匹配。
我该如何解决这个问题?
【问题讨论】:
-
不知道如何解决这个问题?
-
在插入语句中提供列名
-
在
INSERT INTO Account_APInvoiceDetail之后提供列名
标签: sql sql-server