Example SQL Server Buffer HitRatio

Description:
Example to query the SQL Server Buffer HitRatio,
Check the example below:

------------------------------------------------------------------------------------------------------

SELECT (CAST (
           SUM (
              CASE LTRIM (RTRIM (counter_name))
                 WHEN 'buffer cache hit ratio'
                 THEN
                    CAST (cntr_value AS INTEGER)
                 ELSE
                    NULL
              END) AS FLOAT)
        / CAST (
             SUM (
                CASE LTRIM (RTRIM (counter_name))
                   WHEN 'buffer cache hit ratio base'
                   THEN
                      CAST (cntr_value AS INTEGER)
                   ELSE
                      NULL
                END) AS FLOAT))
       * 100
          AS buffercachehitratio
FROM sys.dm_os_performance_counters
WHERE LTRIM (RTRIM ([object_name])) like '%:buffer manager' and [counter_name] like 'buffer cache hit ratio%';