Created
August 19, 2024 12:37
-
-
Save cemerson/e510a043906c366a41e4481bc5a2b3d2 to your computer and use it in GitHub Desktop.
TSQL: Run stored procedure on multiple IDs (deletion example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN TRANSACTION | |
DECLARE @reviewMode int = '0'; | |
DECLARE @password nvarchar(max) = 'password_here'; | |
DECLARE @testStudyIDList NVARCHAR(MAX) = '2791,2793,2843,2844'; | |
DECLARE @testStudyID NVARCHAR(4000); | |
DECLARE @TestStudyIDTable TABLE (ID NVARCHAR(4000)); | |
INSERT INTO @TestStudyIDTable(ID) | |
SELECT Data FROM dbo.Split(@testStudyIDList, ','); | |
DECLARE @RC int; DECLARE @studyID int; | |
DECLARE cur CURSOR FOR SELECT ID FROM @TestStudyIDTable; | |
OPEN cur; | |
FETCH NEXT FROM cur INTO @testStudyID; | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
EXECUTE @RC = [dbo].[DeleteAllStudyData] | |
@testStudyID, @reviewMode, @password; | |
FETCH NEXT FROM cur INTO @testStudyID; | |
END; | |
CLOSE cur; | |
DEALLOCATE cur; | |
ROLLBACK; | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment