No wonder the confusion. That looks like a different question.
Does this query work for you?:
-- CHANGE LOGINNAME TO THE LOGIN YOU'RE INTERESTED IN
set nocount on
declare @name sysname,
@SQL nvarchar(600)
if exists (select [id] from tempdb..sysobjects where [id] = OBJECT_ID ('tempdb..#tmpTable'))
drop table #tmpTable
CREATE TABLE #tmpTable (
[DATABASENAME] sysname NOT NULL ,
[USER_NAME] sysname NOT NULL,
[ROLE_NAME] sysname NULL,
[LOGIN_NAME] sysname NULL)
declare c1 cursor for
select name from master.dbo.sysdatabases
open c1
fetch c1 into @name
while @@fetch_status >= 0
begin
select @SQL =
'insert into #tmpTable
select N'''+ @name + ''', a.name, c.name, d.name
from ' + QuoteName(@name) + '.sys.database_principals a
left join ' + QuoteName(@name) + '.sys.database_role_members b on b.member_principal_id = a.principal_id
left join ' + QuoteName(@name) + '.sys.database_principals c on c.principal_id = b.role_principal_id
left join ' + 'master.sys.server_principals d on d.sid = a.sid
where a.name <> ''dbo'' and a.is_fixed_role = 0
and a.name = ''LOGINNAME'''
/* Insert row for each database */
execute (@SQL)
fetch c1 into @name
end
close c1
deallocate c1
select * from #tmpTable
Greg