Question : Using a Table variable to hold sp_MSforeachdb values

like a temp table, can the foll code be tweaked that a table variable can be used to hold the values returned by the sp?

thanks
1:
2:
3:
4:
5:
EXEC sp_MSforeachdb '
DECLARE @TestTable TABLE (DBNAME varchar(200), TableName varchar(200))
INSERT INTO @TestTable SELECT DISTINCT ''?'' DBNAME , name TableName FROM [?].sys.all_objects where type = ''u'' 
SELECT * FROM @TestTable
'

Answer : Using a Table variable to hold sp_MSforeachdb values

Apparently yes.

declare @testTable TABLE (DBNAME varchar(200), TableName varchar(200))
INSERT @TestTable
EXEC sp_MSforeachdb '
SELECT DISTINCT ''?'' DBNAME , name TableName FROM [?].sys.all_objects where type = ''u''
'
SELECT * FROM @TestTable
Random Solutions  
 
programming4us programming4us