Q&A for professional and enthusiast programmers
Select 'Select ''' + Replace([Name],'','') + ''' As [DatabaseName], ' + 'Count(*) As [Count], (SELECT COUNT(*) FROM [' + [Name] + ']..Users fun WHERE fun.AccountId Is NULL) As [Nulls] ' + 'From [' + [Name] + ']..Users fu Join Users u ON fu.AccountId=u.AccountId ' + ' UNION ALL ' From sys.Databases Where Name Like '%'