• Hi,

    please follow the link below for more information.

    http://www.codeproject.com/Articles/459536/SQL-Server-Applying-Filter-on-sp_MSforeachDB

    u can use sys.databases also.

    Thanks&Regards,

    SQL server DBA