【发布时间】:2020-12-19 16:38:27
【问题描述】:
我在创建以下存储过程时遇到错误,该过程会从数据表中将新记录插入表中
CREATE PROCEDURE [dbo].[SP_Cde_SecureList_Upsert]
@SecureList SecureList READONLY,
@ListType varchar(20)
AS
BEGIN
IF(@ListType='FETCHDETAILS')
SELECT * FROM TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST
ELSE
BEGIN
INSERT INTO TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST([CardRefID], [KEY], [MIS_Field1], [MIS_Field2], [ValidatingCarrier]
, [OtherCarriers], [Card Vendor], [Card], [Expiration], [Precedence], [AlertEmail], [maxTktAmt], [IRP_remark])
SELECT [CardRefID], [KEY], [MIS_Field1], [MIS_Field2], [ValidatingCarrier]
, [OtherCarriers], [Card Vendor], [Card], [Expiration], [Precedence], [AlertEmail], [maxTktAmt], [IRP_remark] FROM @SecureList;
END
END
GO
错误:
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'CardRefID'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'MIS_Field1'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'MIS_Field2'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 12 [Batch Start Line 60]
Invalid column name 'ValidatingCarrier'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'OtherCarriers'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Card Vendor'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Card'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Expiration'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'Precedence'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'AlertEmail'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'maxTktAmt'.
Msg 207, Level 16, State 1, Procedure SP_Cde_SecureList_Upsert, Line 13 [Batch Start Line 60]
Invalid column name 'IRP_remark'.
Completion time
这很奇怪,因为列名是正确的
下面是我的 SP 和表的标题/列的屏幕截图,我正在尝试从数据表中插入数据
SP and table column details screenshot
如果我确实从数据表中选择 *
CREATE PROCEDURE [dbo].[SP_Cde_SecureList_Upsert]
@SecureList SecureList READONLY,
@ListType varchar(20)
AS
BEGIN
IF(@ListType='FETCHDETAILS')
SELECT * FROM [dbo].[TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST]
ELSE
BEGIN
INSERT INTO [dbo].[TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST](CardRefID, [KEY], MIS_Field1, MIS_Field2, ValidatingCarrier
, OtherCarriers, [Card Vendor], Card, Expiration, Precedence, AlertEmail, maxTktAmt, IRP_remark)
SELECT * FROM @SecureList;
END
END
GO
我收到一个错误
Msg 120, Level 15, State 1, Procedure SP_Cde_SecureList_Upsert, Line 10 [Batch Start Line 60]
The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.
【问题讨论】:
-
你遇到了什么错误。这是如何在 C# 中使用的?
-
@MintMoney 。 . .错误消息似乎很清楚。
TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST或@SecureList之一(或两者)没有这些列 -
如果您看到我的屏幕截图(最后一部分),则 TBL_TICKETING_ALTERNATE_CREDIT_CARD_LIST 包含所有这些列,并且数据表正在从 C# 代码传递这些值。
-
@GordonLinoff - 有什么意见吗?
-
您收到此错误是因为您的表的列数比您的插入语句多或少,并且您使用 * 从表中进行选择。虽然使用 * 没有任何问题,但更好的做法是按名称指定列,以防止将来修改表时出错。
标签: sql database stored-procedures datatable