Sites where a user doesn't have an account on

9

Please login or register to vote for this query.

(click on this box to dismiss)

Drupal Answers

Q&A for Drupal developers and administrators

-- all databases
declare db_c cursor for select [name] 
                        from sys.databases 
                        where database_id > 5 -- skip master, temp, model, msdb, Data.SE

declare @db_c_name sysname -- holds name of db after fetch
declare @sql nvarchar(max) -- holds build up sql string

-- result table
create table #accounts (databasename nvarchar(250), id int, displayname nvarchar(40));
create table #databases (databasename nvarchar(250));

open db_c
fetch next from db_c into @db_c_name
while(@@FETCH_STATUS = 0)
begin
    set @sql = N'use '+ QUOTENAME(@db_c_name) + ';
    insert into #accounts 
    select ''' + @db_c_name + ''', id, displayname
      from users
      where accountid = ' + CAST(##AccountId## as nvarchar) + ';
    insert into #databases select ''' + @db_c_name + '''';
    exec (@sql)
    fetch next from db_c into @db_c_name
end;
close db_c;
deallocate db_c;

select * from #databases as d left outer join #accounts as a
  on d.databasename = a.databasename;

Enter Parameters

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