0
我有person
表和peSubmbitedFL
列。我需要編寫一個存儲過程來將此列中的數據從0更新爲1,以獲取特定ID的列表。使用存儲過程更新列中的某些數據
我的代碼出錯了?
ALTER PROCEDURE [dbo].[pr_PersonAssignSubmitted]
@AppIDs varchar(8000),
@RetVal int OUTPUT
AS
SET @RetVal = 0
SET XACT_ABORT ON
BEGIN TRAN
DECLARE @AppID int
DECLARE CURSOR_COLUMNS CURSOR LOCAL FOR
SELECT item
FROM dbo.[fn_ParseStrList](@AppIDs, ',') --pretvora od string vo tabela
WHERE CAST(item as int) IN (SELECT pePersonID
FROM Person
WHERE pePersonID = @AppID)
OPEN CURSOR_COLUMNS
FETCH NEXT FROM CURSOR_COLUMNS INTO @AppID -- item stavi go vo @AppID
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE Person
SET pePersonID = @AppID, peIsSubmittedFL = 1;
FETCH NEXT FROM CURSOR_COLUMNS INTO @AppID
END
IF @@ERROR = 0 SET @RetVal = 1
COMMIT TRAN
SET XACT_ABORT OFF
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE Person
SET pePersonID = @AppID, peIsSubmittedFL = 1;
FETCH NEXT FROM CURSOR_COLUMNS INTO @AppID
END
IF @@ERROR = 0
SET @RetVal = 1
COMMIT TRAN
SET XACT_ABORT OFF
我想你'UPDATE'的說法應該是'UPDATE人所設定的peIsSubmittedFL = 1 WHERE pePersonID = @ AppID' – Abhishek
@Abhishek是的,這就是我想的太多,否則,OP在這裏試圖實現什麼是沒有意義的。 –
@ M.Ali - 是的,反正OP沒有具體說明'代碼中的錯誤',你的答案會做這項工作 – Abhishek