I have a table containing SQL statements stored as VARCHAR
. I want to count how many rows each statement returns. I'm reading the statements into a temp variable called @SQL
, and doing something like this as I cursor through each row:
set @SQL = (select sqlcode from t1 where id = @id)
set @SQL = 'Select @id, count(*) from (' + @SQL + ') as t';
insert into #myresults
exec(@SQL)
This works just fine unless until one of the SQL statements itself uses temp tables or cursors.