I have a stored procedure in which I use a cursor to parse arrays separated by semi-colons (eg Marketing;Diligence;Deal Flow
) is returned in three separate rows with each value in its own row. The procedure/cursor works perfectly when run in a fresh session. However if I re-run the procedure within the same session, the cursor returns 0 rows.
DECLARE @category NVARCHAR(MAX)
DECLARE cursor_product CURSOR LOCAL STATIC FORWARD_ONLY READ_ONLY FOR
SELECT DISTINCT category AS val
FROM #temp;
OPEN cursor_product;
CREATE TABLE #temp5
(
Name varchar(max)
)
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO #temp5
EXEC sp_ParseArray @category, ';'
FETCH NEXT FROM cursor_product INTO @category
END;
CLOSE cursor_product;
DEALLOCATE cursor_product;