Sp_who3

USE [master]
GO

/****** Object: StoredProcedure [dbo].[sp_who3] Script Date: 24/06/2016 15:29:28 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[sp_who3]
AS
——————————————————————————————————–
— mimics sp_who2 with query text
— SPID , Status , Login , HostName , BlkBy , DBName , Command , CPUTime , DiskIO , LastBatch , ProgramName , SPID , REQUESTID
——————————————————————————————————–
— DATE MODIFIED BY DESCRIPTION

——————————————————————————————————–

set nocount on

select
convert(char(5),es.session_id) as SPID, er.status as Status, es.login_name as Login, es.host_name as HostName, convert(char(5),isnull(blocking_session_id,”)) as BlkBy,
db_name(es.database_id) as [database], command, convert(varchar,er.cpu_time) as
CPUTime, convert(varchar,er.total_elapsed_time) as ElapsedTime, convert(varchar,er.reads) as Reads, convert(varchar,er.writes) as Writes, er.start_time as StartTime,
isnull(wait_type,”) as WaitType, convert(char(5),wait_time) as WaitTime, es.program_name as Program, es.client_interface_name as Provider, isnull(st.text,”) as SQLText,
convert(char(5),request_id) as RequestID
from
sys.dm_exec_sessions es
join sys.dm_exec_requests er on er.session_id=es.session_id
outer apply sys.dm_exec_sql_text(sql_handle) st
GO