>Hi All, I have a couple of hundred tables in SS that have a prefix of IOM in their name, they all have the same structure which is a single column. What I want to do is create a master table containing all the records of these tables - obvously I don't want to do this manually - any ideas ?
Try:
declare @SQL nvarchar(max)
select @SQL = coalesce(@SQL + CHAR(13),'') + ';INSERT INTO Master SELECT * FROM ' +
quotename(Table_Schema) + '.' + quotename(Table_Name) from INFORMATION_SCHEMA.Tables
where Table_Name LIKE 'IOM%'
EXECUTE (@SQL)
If it's not broken, fix it until it is.
My Blog