SQL Programming: Saving/Listing each row in a SQL SELECT query results set

While debugging various enterprise management software’s that ship with a data hosted on SQL database, systems engineers requires to run various SQL queries to get the underlying information. While debugging the results returned from the query, one need to be able to observer each row returned by the SQL query. Here is quick way to run your any DQL query and verify the results at each row.

This will be essentially handy when you want to inspect the temporary data in your SQL program.

 
DECLARE @action_code INT
DECLARE row_cursor CURSOR FOR
SELECT ACTUALACTION_IDX FROM test_gunnalag

OPEN row_cursor

-- Perform the first fetch.
FETCH NEXT FROM row_cursor INTO @action_code

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
   -- This is executed as long as the previous fetch succeeds.
	SELECT ACTUALACTION FROM test_gunnalag WHERE ACTUALACTION_IDX = @action_code
	FETCH NEXT FROM row_cursor INTO @action_code
END

CLOSE row_cursor
DEALLOCATE row_cursor