declare @command varchar(max) set @command = 'SELECT ''?'',* from [?].dbo.sysusers where [name] NOT IN (''db_accessadmin'',''db_backupoperator'',''db_datareader'',''db_datawriter'',''db_ddladmin'',''db_denydatareader'',''db_denydatawriter'',''db_owner'',''db_securityadmin'',''dbo'',''guest'',''INFORMATION_SCHEMA'',''public'',''sys'')' print (@command) exec sp_MSforeachdb @command