with [BlockedQueries] as
(
select
der.session_id, der.blocking_session_id, der.start_time,
der.total_elapsed_time,
SUBSTRING(text, (statement_start_offset/2)+1,
((CASE statement_end_offset
WHEN -1 THEN DATALENGTH(text)
ELSE statement_end_offset
END - statement_start_offset)/2) + 1) AS sqltext
from
sys.dm_exec_requests as der
cross apply
sys.dm_exec_sql_text (der.sql_handle) as dest
where
blocking_session_id <> 0
union all
select
c.session_id, c.blocking_session_id, c.start_time, c.total_elapsed_time,
dest.text
from
[BlockedQueries] p, sys.dm_exec_requests as c
cross apply
sys.dm_exec_sql_text (c.sql_handle) as dest
where
p.[blocking_session_id] = c.[session_id]
)
When running this on SQL Server 2008, I get the following error.
Msg 102, Level 15, State 1, Line 31
Incorrect syntax near ‘)’.
I’m trying to run the one in this link
under Blocked Queries Agent.
Any pointers will be appreciated.
You need something after the with clause (and normally, a
;before it)