if object_ID('TempDB..#Stats') is not null drop table #Stats create table #Stats (TableName varchar(128), Statistics_Name varchar(128), Statistics_Keys varchar(128)) if object_ID('TempDB..#Stats_Temp') is not null drop table #Stats_Temp create table #Stats_Temp (Statistics_Name varchar(128), Statistics_Keys varchar(128)) exec sp_MSforeachtable 'insert into #Stats_Temp execute sp_helpstats ''?'', ''ALL''','?','insert into #Stats select ''?'', * from #Stats_Temp','delete from #Stats_Temp' select * from #Stats where Statistics_Name like '_WA%'