Alternate for sp_msforeachdb to resolve database name including "-"

  • Hi All,

    I am having a database named DA-Profiler.

    While running the below query

    exec sp_msforeachdb 'use ? exec sp_spaceused'

    i got the following error

    “Could not locate entry in sysdatabases for database 'DA'. No entry found with that name. Make sure that the name is entered correctly.”

    The query is working fine with all other databases except this database.

    This error occurred as the database name contains “–“ .

    Can anyone suggest me a work around for this without renaming the database.

    Thanks in advance.

  • Try this

    exec sp_msforeachdb 'use [?] exec sp_spaceused'

    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
  • Thank You so much.

    It works.

    🙂

Viewing 3 posts - 1 through 2 (of 2 total)

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