I have a table that has list of stored procedures.
I am using a cursor to then loop through and call and capture the result of each stored procedure (they all return 0 or 1).
So I have:
DECLARE @PROC_ID INT,
@PROC_NAME VARCHAR(50)
SELECT *
INTO #MY_PROCS
FROM TABLE_PROCS
DECLARE MY_CURSOR CURSOR FOR
SELECT PROC_ID, PROC_NAME
FROM TABLE_PROCS
OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @PROC_ID, @PROC_NAME
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @PROC_RESULT = .......
UPDATE #MY_PROCS SET PROC_RESULT = @PROC_RESULT WHERE PROC_ID = @PROC_ID
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
DROP TABLE #MY_PROCS
I was reading on cursors, and read I should be setting it as READ ONLY and NO LOCK if possible.
Also, should I be using a table variable instead of a temp table?
Is it possible to do this w/o a cursor?
The most efficient cursor is going to be, at least in all of my testing:
Now, it’s impossible for us to know if you can do this without a cursor. You’ve conveniently left out the only information we could have used to tell you that. It seems you are calling a procedure for each call, but you can’t be doing that with SELECT. And then you update a table with the result, but you drop the table.