Last active
June 10, 2021 13:53
-
-
Save SteGriff/35caa1976f240850a74bed8ffedf7649 to your computer and use it in GitHub Desktop.
Running SQL queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
d.name, | |
t.text, | |
r.total_elapsed_time/1000 as [Time], | |
r.blocking_session_id, | |
SUBSTRING(t.text,r.statement_start_offset/2 +1, | |
(CASE WHEN r.statement_end_offset = -1 | |
THEN LEN(CONVERT(NVARCHAR(MAX), t.text)) * 2 | |
ELSE r.statement_end_offset END - | |
r.statement_start_offset)/2) | |
AS 'TSQL-Query' | |
FROM sys.dm_exec_requests r | |
JOIN sys.databases d on d.database_id = r.database_id | |
CROSS APPLY sys.dm_exec_sql_text(sql_handle) t | |
order by time desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment