• I use the bitwise and operator (&) to pull the status column apart for inspection.

    For example:

    SELECT

    name

    FROM

    master..sysdatabases

    WHERE

    name NOT IN ('tempdb')

    AND

    status & 512 <> 512

    512 means the database is offline. This query returns a list of database names where the database is online.