Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Could not locate entry in sysdatabases for database Expand / Collapse
Author
Message
Posted Wednesday, December 15, 2010 8:36 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 11, 2015 12:22 PM
Points: 381, Visits: 690
I am trying to run the following and I get the error "Could not locate entry in sysdatabases for database".
sp_msforeachdb 'USE ?;select distinct db_name()'

I know that one of the db name is longer.

Any ideas?

Thanks.
Post #1035205
Posted Wednesday, December 15, 2010 8:44 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:05 AM
Points: 45,102, Visits: 43,192
Does it change anything if you wrap the dbname in [] in the use statement?

sp_msforeachdb 'USE [?];select db_name()'

p.s. No need for distinct, you're selecting a single constant value.



Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1035222
Posted Wednesday, December 15, 2010 8:48 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 11, 2015 12:22 PM
Points: 381, Visits: 690
Adding brackets around "[?]" was a common sense and I am missing it. Thank you very much.
Post #1035225
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse