March 31, 2021 at 1:03 pm
Hi
Anyone got a query that will find sessions running a particular piece of SQL text ? and bring back output like Kill <Session ID>;
Half way there in terms of finding the session, I just need to include where the sql text like "%select blah blah blah%
SELECT 'KILL ' + CONVERT(VARCHAR(11), session_id) + N';'
FROM sys.dm_exec_sessions
WHERE login_name = N'JOE_BLOGGS';
thanks in advance
March 31, 2021 at 2:43 pm
You could do something like and filter as needed,
SELECT * FROM sys.dm_exec_requests er
INNER JOIN sys.dm_exec_sessions ses on er.session_id = ses.session_id
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) sql_text
March 31, 2021 at 3:55 pm
I need to select all SIDs of a particular user who is running a particular piece of code, there in lies the challenge 😉
March 31, 2021 at 3:56 pm
And produce a kill script from that select.
April 1, 2021 at 11:56 pm
I just need to include where the sql text like "%select blah blah blah%
I'm curious... WHY?
--Jeff Moden
Change is inevitable... Change for the better is not.
April 2, 2021 at 12:43 am
Because someone who shouldn't have had rights to execute his own SQL statements instead of being limited to existing, properly written stored procedures etc?
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply