sp_msforeachdb

  • Hello All,

    Does anyone know how to make sp_msforeachdb work with database name starting with number? It is not working in our case. The DB started with character is fine.

    Thank you for your help.

     

    David

  • Brows the Internet. There is an enourmous ammout of information about undocumented sp's.

    http://www.databasejournal.com/features/mssql/article.php/1490641

    Regards,

    Gkramer

  • It runs fine on a SQL Server 7 Standard Edition. Haven't a SQL2K setup available right now. What release are you using?

    Greetz,
    Hans Brouwer

  • Did you try enclosing the dbname in square brackets?

    ie exec sp_msforeachdb "use [?]; select * from sysobjects"



    Shamless self promotion - read my blog http://sirsql.net

  • Dear All,

    Thanks all for your reply. Here is my script and I tried Nicholas's suggestion. Both of them are not working with those database name started with number.

    set quoted_identifier off

    go

    sp_msforeachdb @Command1="print '?' Select substring(name, 1, 30) TABLE_NAME

    from ?..sysobjects"

    Thanks

  • It looks like you're trying to get a list of sysobjects for every database. If so, copy and paste the following in Query Analyzer:

    sp_MSforeachdb 'select substring(name, 1, 30) ''[?]'' from [?]..sysobjects'

    This will list all the sysobjects with the database name as the column title. If you type it in, note that where you see '' (two single quotes looks like a double quote), it is actually two ' (single quotes). I noticed you're using double quotes.

  • Thanks Accent Care and Nicholas. It worked.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply