• Try using

    SELECT name

    FROM master.dbo.sysdatabases

    WHERE status&512 = 0

    and status&32 = 0

    Any databases that are offline or being loaded will be skipped.

    For a list of all the status values take a look at this post by

    Lowell

    David Bird