I ran across a script here:[url]http://sqlserverplanet.com/dmv-queries/a-better-sp_who2-using-dmvs-sp_who3/[/url]SELECT SPID = er.session_id ,BlkBy = er.blocking_session_id ,ElapsedMS = er.total_elapsed_time ,CPU = er.cpu_time ,IOReads = er.logical_reads + er.reads ,IOWrites = er.writes ,Executions = ec.execution_count ,CommandType = er.command ,ObjectName = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' + OBJECT_NAME(qt.objectid, qt.dbid) ,SQLStatement = SUBSTRING ( qt.text, er.statement_start_offset/2, (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2 ELSE er.statement_end_offset END - er.statement_start_offset)/2 ) ,Status = ses.status ,[Login] = ses.login_name ,Host = ses.host_name ,DBName = DB_Name(er.database_id) ,LastWaitType = er.last_wait_type ,StartTime = er.start_time ,Protocol = con.net_transport ,transaction_isolation = CASE ses.transaction_isolation_level WHEN 0 THEN 'Unspecified' WHEN 1 THEN 'Read Uncommitted' WHEN 2 THEN 'Read Committed' WHEN 3 THEN 'Repeatable' WHEN 4 THEN 'Serializable' WHEN 5 THEN 'Snapshot' END ,ConnectionWrites = con.num_writes ,ConnectionReads = con.num_reads ,ClientAddress = con.client_net_address ,Authentication = con.auth_schemeFROM sys.dm_exec_requests erLEFT JOIN sys.dm_exec_sessions sesON ses.session_id = er.session_idLEFT JOIN sys.dm_exec_connections conON con.session_id = ses.session_idCROSS APPLY sys.dm_exec_sql_text(er.sql_handle) as qtOUTER APPLY( SELECT execution_count = MAX(cp.usecounts) FROM sys.dm_exec_cached_plans cp WHERE cp.plan_handle = er.plan_handle) ecORDER BY er.blocking_session_id DESC, er.logical_reads + er.reads DESC, er.session_id
I tried to run it but it bombs with these errors:Msg 102, Level 15, State 1, Line 46Incorrect syntax near '.'.Msg 102, Level 15, State 1, Line 52Incorrect syntax near 'ec'.
at the "cross apply". I can't see the error! Can someone point it out to me?