That showed me the right direction. I solved this with the usage of sp_MSforeachdb.
This is the code that works fine for me:
CREATE PROCEDURE [dbo].[CHECK_DATABASES]
AS
BEGIN
SET NOCOUNT ON;
declare @sqlstatement varchar(max)
declare @dbname varchar(100)
IF...