Filter based on DB name (ID)

  • Hi,

    I found such query on internet which help to identify the difference between max logical read and min logical read, but I don't know how I can filter this based on DB name.

    select

    st.text,

    SUBSTRING(st.text, (qs.statement_start_offset / 2) + 1,

    ((CASE statement_end_offset

    WHEN -1 THEN DATALENGTH(st.text)

    ELSE qs.statement_end_offset

    END

    - qs.statement_start_offset) / 2) +1) AS statement_text, execution_count,

    CASE

    WHEN execution_count = 0 THEN NULL

    ELSE total_logical_reads / execution_count

    END AS avg_logical_reads,

    last_logical_reads,

    min_logical_reads,

    max_logical_reads,

    max_elapsed_time,

    CASE

    WHEN min_logical_reads = 0 THEN null

    ELSE max_logical_reads / min_logical_reads

    END AS diff_quota

    FROM sys.dm_exec_query_stats AS qs

    CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) AS st

    ORDER BY diff_quota DESC

    Thanks,

  • There is dbid column in sys.dm_exec_sql_text

    _____________
    Code for TallyGenerator

  • Sergiy (7/21/2016)


    There is dbid column in sys.dm_exec_sql_text

    Thanks, but I can see most of the dbid are null value from sys.dm_exec_sql_text.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply