select DISTINCT o.name, loginname = 
(case when (o.sid = 0x00) then NULL else l.loginname end), user_name(o.gid), o.uid, o.hasdbaccess 
from dbo.sysusers o left join (select sid, loginname, 1 as matched from master.dbo.syslogins) l on l.sid = o.sid where ((o.issqlrole != 1 and o.isapprole != 1 and o.status != 0 and matched is not null) or (o.sid = 0x00) and o.hasdbaccess = 1) and o.isaliased != 1 order by o.name