question

tiwaryrohit143 avatar image
tiwaryrohit143 asked

How to display Database when using sp_foreachdb

Hi, I have written a script. I want to display database name for respective rows or records.

Below is query:- Text file is attached.

Thanks in advance,

Rohit

monitoring-hli-compulsary-cols.txt

sql-server-2008t-sqlsql-server-2012pivot
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered

use ''?'' within the query to reference the current database name

For example

EXEC sp_msforeachdb N'SELECT  ''?'' '
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.