Generate AccountId comparison


Please login or register to vote for this query.

(click on this box to dismiss)

This current version includes redundant stuff because of previous export processes that allowed just the relevant databases to be included. These are easily skipped or deleted from the Text-only results when you past the results into a new query, such as

Artificial Intelligence

Q&A for people interested in conceptual questions about life and challenges in a world where "cognitive" functions can be mimicked in purely digital environment

-- var to hold the complete query as text
declare @sql nvarchar(max)

-- use the STRING_AGG function to get 
Select @sql = STRING_AGG(
-- this is the string for each database
-- [Name] is here the name of the database
N'Select ''' + Replace([Name],'','') + N''' As [DatabaseName], '
+ N'Count(*) As [Count] '
+ N'From [' + convert(nvarchar(max),[Name]) + N']..Users fu Join Users u ON fu.AccountId=u.AccountId '
-- this is what gets used to concatenate all those strings
From sys.Databases
Where database_id >= ##CacheBuster:int## -- skip the first 5 databases, they have nothing for us
and Name Like '%'

print @sql -- this gets shown on the Messages tab

exec(@sql) -- this executes the SQL statement that is the @sql variable

Enter Parameters

Switch to meta site
loading Hold tight while we fetch your results