--SP_WHO2 SELECT  des.session_id ,         des.status ,         des.login_name ,         des.[HOST_NAME] ,         der.blocking_session_id ,         DB_NAME(der.database_id) AS database_name ,         der.command ,         des.cpu_time ,         des.reads ,         des.writes ,         dec.last_write ,         des.[program_name] ,         der.wait_type ,         der.wait_time ,         der.last_wait_type ,         der.wait_resource ,         CASE des.transaction_isolation_level           WHEN 0 THEN 'Unspecified'           WHEN 1 THEN 'ReadUncommitted'           WHEN 2 THEN 'ReadCommitted'           WHEN 3 THEN 'Repeatable'           WHEN 4 THEN 'Serializable'           WHEN 5 THEN 'Snapshot'         END AS transaction_isolation_level ,         OBJECT_NAME(dest.objectid, der.database_id) AS OBJECT_NAME ,         SUBSTRING(dest.text, der.statement_start_offset / 2,                   ( CASE WHEN der.statement_end_offset = -1                          THEN DATALENGTH(dest.text)                          ELSE der.statement_end_offset                     END - der.statement_start_offset ) / 2)                                 AS [executing statement] ,         deqp.query_plan FROM sys.dm_exec_sessions des         LEFT JOIN sys.dm_exec_requests der                       ON des.session_id = der.session_id         LEFT JOIN sys.dm_exec_connections dec                       ON des.session_id = dec.session_id         CROSS APPLY sys.dm_exec_sql_text(der.sql_handle) dest         CROSS APPLY sys.dm_exec_query_plan(der.plan_handle) deqp WHERE   des.session_id <> @@SPID ORDER BY des.session_id -- Get a count of SQL connections by IP address SELECT dec.client_net_address , des.program_name , des.host_name , --des.login_name , COUNT(dec.session_id) AS connection_count FROM sys.dm_exec_sessions AS des INNER JOIN sys.dm_exec_connections AS dec ON des.session_id = dec.session_id -- WHERE LEFT(des.host_name, 2) = 'WK' GROUP BY dec.client_net_address , des.program_name , des.host_name -- des.login_name -- HAVING COUNT(dec.session_id) > 1 ORDER BY des.program_name, dec.client_net_address ; -- Who is connected by SSMS SELECT  dec.client_net_address ,         des.host_name ,         dest.text FROM     sys.dm_exec_sessions des         INNER JOIN sys.dm_exec_connections dec                      ON des.session_id = dec.session_id         CROSS APPLY sys.dm_exec_sql_text(dec.most_recent_sql_handle) dest WHERE   des.program_name LIKE 'Microsoft SQL Server Management Studio%' ORDER BY des.program_name ,         dec.client_net_address -- Session-Level settings Select des.text_size,         des.language ,         des.date_format ,         des.date_first ,         des.quoted_identifier ,         des.arithabort ,         des.ansi_null_dflt_on ,         des.ansi_defaults ,         des.ansi_warnings ,         des.ansi_padding ,         des.ansi_nulls ,         des.concat_null_yields_null ,         des.transaction_isolation_level ,         des.lock_timeout ,         des.deadlock_priority FROM     sys.dm_exec_sessions des WHERE   des.session_id = @@SPID -- Logins with more than one session SELECT login_name ,COUNT(session_id) AS session_count FROM sys.dm_exec_sessions WHERE is_user_process = 1 GROUP BY login_name ORDER BY login_name