I would like to make a t-sql query to check which logins have 'view server state' permission in server type securables. How to achieve this?
This query from mssqltips don't show this:
http://www.mssqltips.com/tip.asp?tip=1718
SELECT prin.[name] [User], sec.state_desc + ' ' + sec.permission_name [Permission]
FROM [sys].[database_permissions] sec
JOIN [sys].[database_principals] prin
ON sec.[grantee_principal_id] = prin.[principal_id]
WHERE sec.class = 0
ORDER BY [User], [Permission];
You need to check the server level permissions. The query you have checks permissions at the database level. You can achieve this by using the sys.server_permissions and sys.server_principals views. Something like:
See this for more information about the sys.server_permissions view.