Answer founddeclare @aTables table( name varchar(30), reg int, used int)declare @tablename varchar(30), @rID int, @used intwhile exists(select * from @awardTables where used = 0) begin select @tablename = name, @used = used from @aTables where used = 0 and reg = @rID exec ('select * from @tablename') update @awardTables set used = 1 where region = @regionID set @regionID = @regionID + 2 end go
When I try to use the @tablename to call exec statement, I getMust declare the variable '@tablename'.I found the answer. I needed to call the exec like this:exec ('select * from' + @tablename)
Cheers