我想根据从 WinForm 传入的行号删除行。当然,ROW_NUMBER()
当你删除一行时,计算的输出总是会更新,所以行号也会改变,所以我想一次性完成,而不是循环。
我有这个代码:
CREATE PROCEDURE Delete_Record (@RowNum INT)
AS
;WITH REC_ROW AS
(
SELECT *, ROW_NUMBER() OVER (ORDER BY [Record Number]) AS RN
FROM User_Data
)
DELETE
FROM REC_ROW
WHERE RN IN (@RowNum)
当我输入:
exec Delete_Record @RowNum = '1,2'
它产生错误:
将数据类型 varchar 转换为 int 时出错。
如果我更改@RowNum INT
为@RowNum varchar(max)
,它只会产生错误消息:
将数据类型 varchar 转换为 bigint 时出错。
当我对值进行硬编码时:
;WITH REC_ROW AS
(
SELECT *, ROW_NUMBER() OVER (ORDER BY [Record Number]) AS RN
FROM User_Data
)
DELETE
FROM REC_ROW
WHERE RN IN (1,2)
它将成功删除第 1 行和第 2 行。问题是如何将其集成到存储过程中并输入'1,2'
传递给IN
子句?