I am running a query against all databases within an instance. There are a few hundered databses with identical schema (tables and all).
This is the query:
EXEC sp_MSforeachdb 'Use ? SELECT top 1 Column1, Column2 from [TableName]where Column3 = ''SpecificValue'' order by Column4 desc'
The query works alright and returns the results which I want, but not in a way I want them.
After I run this query, in the results pane I get one mini table per database so I end up with a few hundered mini tables. It's very impractical, and it forces me to copy results one by one.
Is there a way to rewrite this query so that it returns all results inone table with 2 columns. I would like each row to be like
value of column 1 from db 1 \ value of column2 dfrom db1
value of column 1 from db 2 \ value of column2 dfrom db2
value of column 1 from db 3 \ value of column2 dfrom db3
and so on...