declare @winlogins table
(acct_name sysname,
acct_type varchar(10),
act_priv varchar(10),
login_name sysname,
perm_path sysname)

declare @dbgroups table
(dbname varchar(100),
 db_role varchar(100),
 db_user varchar(100),
 db_type varchar(100))

declare @group sysname
declare @sql varchar(max)
declare @db varchar(100)

set @db = 'demo'

declare recscan cursor for
select name from sys.server_principals
where type = 'G' 
and name not like '%$%' and name not like 'NT SERVICE%'
and is_disabled = 0

open recscan
fetch next from recscan into @group

while @@FETCH_STATUS = 0
begin
	insert into @winlogins
	exec xp_logininfo @group,'members'
	fetch next from recscan into @group
end
close recscan
deallocate recscan

set @sql = 'use ['+@db+'] '+
			'select db_name(),r.name role_name,u.name sql_name,u.type_desc '+
			'from (select * from sys.database_principals where type = ''R'') r '+
			'join sys.database_role_members rm on (r.principal_id = rm.role_principal_id) '+
			'join (select * from sys.database_principals where type != ''R'') u on rm.member_principal_id = u.principal_id '+
			'order by r.principal_id,u.type_desc,u.name'
--print @sql
insert into @dbgroups
exec (@sql)

select 
	r.name role_name,
	u.name db_login,
	u.type_desc,
	wl.login_name win_login,
	wl.acct_type
from (select * from sys.database_principals where type = 'R') r
	join sys.database_role_members rm on (r.principal_id = rm.role_principal_id)
	join (select * from sys.database_principals where type != 'R') u on rm.member_principal_id = u.principal_id
	left join @winlogins wl on u.name = wl.perm_path
order by r.principal_id,u.type_desc,u.name