select
		getdate ()        as check_time ,
		spid              as session_id ,
		kpid              as win_thread_id ,
		blocked           as blocking_session ,
		waittype ,
		waittime ,
		lastwaittype ,
		waitresource ,
		db_name (sp.dbid) as database_name ,
		uid ,
		cpu ,
		physical_io ,
		memusage ,
		login_time ,
		last_batch ,
		ecid ,
		open_tran ,
		status ,
		sid ,
		hostname ,
		program_name ,
		hostprocess ,
		cmd ,
		nt_domain ,
		nt_username ,
		net_address ,
		net_library ,
		loginame ,
		context_info ,
		request_id ,
		sp.sql_handle ,
		sp.stmt_start ,
		sp.stmt_end ,
		text              as full_text ,
		(
			select top 1
				   substring (
								 st.text ,
								 stmt_start / 2 + 1,
								 ((case
								   when stmt_end = -1 then (len (convert (nvarchar(max), st.text)) * 2)
								   else stmt_end
								   end
								  ) - stmt_start
								 ) / 2 + 1
							 )
		)                 as sql_statement
	from
		sys.sysprocesses                          sp
	cross apply sys.dm_exec_sql_text (sql_handle) as st
	where
		blocked <> 0

作者 uoscn