This worked for me.
I declared a temp table and used it to receive the values from the select statement.
Something like below.
declare @i int
declare @v int create table #t (val int) insert into #t exec ('declare @i int set @i = 0 select @i+1') select * from #t
declare @i int declare @v int create table #t (val int) insert into #t exec ('declare @i int set @i = 0 select @i+1') select * from #t