I am trying to list the logins in MS SQL database from sys.server_principals table.
But I am trying to get only those logins which have valid databases, I can see that the sys.server_principals table have logins which are associated to old default databases which does not exist.
I am trying to make something like:
SELECT * FROM sys.server_principals where default_database_name = (select name from sys.databases) AND type_desc = 'SQL_LOGIN'
I would really appreciate if you could help me with a query.