Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

DMV use Cross Apply and too much result

$
0
0

Hi

Here are my code for query DMV, but some column Is repeated, how can I filter it (last_exection_time) ?

I just wnat find T-SQL query information(only select), and it must include query text、targert db、source application(from connection string )、and other needed !

You can change database name and where conditional, for your testing ! Thanks

SELECT DB_NAME(DMV_QueryText.dbid) as 'DBName', 
       DMV_Sessions.program_name as 'ApplicationName',
       DMV_QueryText.text as 'SQL Statement',
       execution_count as 'Count',
    --last_rows, (for SQL 2012 only)
last_execution_time as 'Last Execution Time(ms)',
last_worker_time  as 'Last Worker Time(ms)',
last_physical_reads as 'Last Physical Reads(ms)',
last_logical_reads as 'Last Logical Reads(ms)',
last_logical_writes as 'Last Logical Writes(ms)',
last_elapsed_time as 'Last Elapsed Time(ms)'
FROM sys.dm_exec_query_stats AS DMV_QueryStats
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS DMV_QueryText
cross Apply  sys.dm_exec_sessions as DMV_Sessions
WHERE DMV_QueryText.objectid is null and  DB_Name(DMV_QueryText.dbid)='YourDB' and PatIndex('select %',DMV_QueryText.text)>0
and DMV_Sessions.program_name  is not null and DMV_Sessions.program_name in('app1','app2','app3','app4')

-- order by  DMV_QueryStats.execution_count desc
order by DMV_QueryStats.last_worker_time desc
Repeating field


my407sw



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>