USE Lis_Blob
GO
select DISTINCT 'EXEC sp_dropuser ''' +
o.name + ''''
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
and
o.name not in ('dbo', 'guest', 'sys')