DECLARE @command NVARCHAR(max) = ''; WITH allData AS (SELECT req.session_id , req.start_time , cpu_time 'cpu_time_ms' , object_name(st.objectid,st.dbid) 'ObjectName' , substring (REPLACE (REPLACE (SUBSTRING (ST.text , (req.statement_start_offset/2) + 1 , ( (CASE statement_end_offset WHEN -1 THEN DATALENGTH(ST.text) ELSE req.statement_end_offset END - req.statement_start_offset)/2) + 1) , CHAR(10), ' '), CHAR(13), ' '), 1, 512) AS statement_text FROM sys.dm_exec_requests AS req CROSS APPLY sys.dm_exec_sql_text(req.sql_handle) as ST ) select @command = @command + concat('kill ', session_id) from allData WHERE statement_text like 'select that I need to kill %' exec (@command); waitfor delay '00:00:01'; PRINT 'here we go again...'; GO 100000