I have a question about using cursor. I want to UNION the multiple table with stored procedure.
If i used cursor, it overlaps with the last event.
This is my Code.
-- CURSOR DECLARE @parm1 int, @parm2 int -- 1. CURSOR DECLARE DECLARE test_cur CURSOR FOR -- TABLE SELECT SELECT parm1 , parm2 --, COUNT(parm1) FROM dbo.testDB GROUP BY parm1, parm2 ORDER BY parm1 ASC -- 2. CURSOR for-loop OPEN test_cur FETCH NEXT FROM test_cur INTO @parm1, @parm2 --3. read row WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM test_cur INTO @parm1, @parm2 EXEC TEST_DEAL @parm1, @parm2, 1 -- parameter1, parameter2, parameter3 END -- CURSOR CLOSED CLOSE test_cur DEALLOCATE test_cur You know, the procedure is make a new table using SELECT ~ INTO clause.
And stored procedure function make a table using temp-table.
As a result, I create multiple tables using the cursor, and then combine all tables using UNION.
Please check my code and comment this issue.
https://stackoverflow.com/questions/66485732/how-to-union-table-using-cursor March 05, 2021 at 10:06AM
没有评论:
发表评论