DECLARE @sql varchar(MAX) SET @sql = 'INSERT INTO Whatever SELECT * FROM ' + @fname EXECUTE (@sql)Also
-- Invalid. It's not C# or Java -- While @fname != null -- Correct While @fname IS NOT NULL>Thanks Sergey, how do loop through the list of tables ?, I've tried selecting a table name into a variable - but how do I select from a table using my variable ?
> >declare @fname varchar(max) > >Select @fname = min(table_name) >from information_schema.tables >where table_type = 'base table' >and left(table_name,3) = 'IOM' > >-- So far so good > >While @fname != null >begin > >-- How do I now select from @fname into a table ? > >Select @fname = min(table_name) >from information_schema.tables >where table_type = 'base table' >and left(table_name,3) = 'IOM' >and table_name > @fname > >end > >