SELECTDISTINCT SUBSTRING(qt.TEXT, (er.statement_start_offset/2)+1, ((CASE er.statement_end_offset WHEN-1THENDATALENGTH(qt.TEXT) ELSE er.statement_end_offset END - er.statement_start_offset)/2)+1) AS query_sql, er.session_id AS pid, er.status ASstatus, er.command AS command, sp.hostname AS hostname, DB_NAME(sp.dbid) AS db_name, sp.program_name AS program_name, er.cpu_time AS cpu_time, er.total_elapsed_time AS cost_time FROM sys.sysprocesses AS sp LEFTJOIN sys.dm_exec_requests AS er ON sp.spid = er.session_id CROSSAPPLY sys.dm_exec_sql_text(er.sql_handle) AS qt WHERE1 = CASEWHEN er.status IN ('RUNNABLE', 'SUSPENDED', 'RUNNING') THEN1WHEN er.status = 'SLEEPING'AND sp.open_tran > 0THEN1ELSE0END AND er.command = 'SELECT' ORDERBY er.total_elapsed_time DESC