Table varible inside a cursor loop
<p>I noticed that when I declare a table variable inside a cursor loop, the variable persist trough the cursor lifetime. my question is, if there is a way to declare the variable in such a way that it's lifetime will only persist trough the iteration? here is a sample:</p>

<pre><code>DECLARE @SourceTable TABLE(Id INT IDENTITY(1,1),Remarks VARCHAR(10))
INSERT INTO @SourceTable VALUES ('First')
INSERT INTO @SourceTable VALUES ('Second')
INSERT INTO @SourceTable VALUES ('Third ')

/* declare variables */
DECLARE @variable INT

DECLARE my_cursor CURSOR FAST_FORWARD READ_ONLY FOR SELECT Id FROM @SourceTable

OPEN my_cursor

FETCH NEXT FROM my_cursor INTO @variable

WHILE @@FETCH_STATUS = 0
BEGIN
    --Dose not creates a new instance
    DECLARE @VarTable TABLE (Remarks VARCHAR(10))

    INSERT INTO @VarTable
    SELECT TOP 1 Remarks FROM @SourceTable
    WHERE Id = @variable


    --Works as intended if you drop when done
    CREATE TABLE #TempTable  (Remarks VARCHAR(10))

    INSERT INTO #TempTable
    SELECT TOP 1 Remarks FROM @SourceTable
    WHERE Id = @variable

    DROP TABLE #TempTable

    FETCH NEXT FROM my_cursor INTO @variable
END

CLOSE my_cursor
DEALLOCATE my_cursor

SELECT * FROM @VarTable
</code></pre>

<p>But it gets even more confusing. if you try to query the temptable outside the cursor, you will get an error. it appears as if temp table is the only correct way for such situation?</p>