views:

10

answers:

1

I am running a dynamic sql command with sp_msforeachdb for each database. However the command bombs for a certain database.

How is '?' used to display the database name when the error happens? I tried using it in a Catch statement but my syntax is wrong.

A: 

Just use DB_NAME()

EXEC sp_msforeachdb 'USE ? SELECT DB_NAME() ...do stuff'
gbn