# Generic DB Query Plugin SAP HANA

**URL:** <https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492>\
**Category:** Extensions\
**Tags:** databases, sap, extensions, queues\
**Created:** [January 8, 2024, 10:57am UTC](https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492 "2024-01-08T10:57:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlos\_carreno](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/carlos_carreno/32/28820_2.png) [@carlos\_carreno](https://community.dynatrace.com/u/carlos_carreno)\
**Post date:** [January 8, 2024, 10:57am UTC](https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492/1 "2024-01-08T10:57:07Z")

</div>

Good morning Dynatrace community, for this project, the ‘Generic DB Query Plugin’ extension was implemented to connect to a standard SAP HANA database ‘VBAK’, with the sole purpose of counting the number of times a record is repeated in the database.

_ **“Example of a database taken from an internet image.”** _

 ![carlos_carreno_0-1704710227578.png](https://global.discourse-cdn.com/dynatrace/original/3X/4/b/4b42977d3266ee90f1e9ef131dd6420094a20f3a.png)

For the columns in this database, the following queries were executed:

```markup
SELECT COUNT(AUDAT) AS CANTIDAD, AUDAT
FROM xxxxxx.VBAK
where ERNAM='APL_USRPI'
and AUART='ZB2B'
and AUDAT='01/01/2024'
GROUP BY AUDAT

SELECT COUNT(AUDAT) AS CANTIDAD, AUDAT 
FROM xxxxxx.VBAK 
WHERE ERNAM='APL_USRPI' 
AND AUART='ZNAC'
AND AUDAT>='01/01/2024'
GROUP BY AUDAT

SELECT COUNT(AUDAT) AS CANTIDAD, AUDAT 
FROM XXXXX.VBAK 
WHERE ERNAM ='CNX_ERP_CPI' 
AND AUART ='ZB2C'
AND AUDAT>='01/01/2024'
GROUP BY AUDAT

```

With the goal of bringing me the total number of times the condition is met and thus being able to know that total of records and maintaining control, but the result it yields is the number of times the system goes and performs the query.

With the following configuration in the query in Data Explorer.

```markup
custom.db.query:splitBy("dt.entity.custom_device",query_name,column):count:sort(value(avg,descending)):limit(20)

custom.db.query.statistics.query.rows:splitBy("dt.entity.custom_device",query_name):count:sort(value(avg,descending)):limit(20)

```

SpoilerThe ‘rows’ query was performed in an attempt to establish a relationship between the number of columns versus the records.

Within a time period of 15 minutes, this is the result it yields for me.

 ![carlos_carreno_1-1704710728986.png](https://global.discourse-cdn.com/dynatrace/original/3X/6/b/6be808b52fd214276b214da5b9ca4a1cc34166ea.png)

I’ve explored all possible forms in the query, but still feel that something isn’t right. I hope to find help, thank you.

**“Example of expected results.”**

 ![carlos_carreno_3-1704711184761.png](https://global.discourse-cdn.com/dynatrace/original/2X/3/3a15e30f8a2ce6a71193551e7794daaea619d809.png)

 ![carlos_carreno_4-1704711384797.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/f3536aa0a9e1ea31bc7e8285473531a8861fc893.png)

---

<div class="post-metadata">

**Author:** ![Miguel\_RinconG](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/miguel_rincong/32/29455_2.png) [@Miguel\_RinconG](https://community.dynatrace.com/u/Miguel_RinconG)\
**Post date:** [January 8, 2024, 1:07pm UTC](https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492/2 "2024-01-08T13:07:10Z")

</div>

Hello Carlos,

The&nbsp;‘Generic DB Query Plugin’ extension is deprecated. The new extension 2.0:&nbsp;[SQL data source — Dynatrace Docs](https://docs.dynatrace.com/docs/extend-dynatrace/extensions20/data-sources/sql)

Please check this example:&nbsp;[SAP Hana Database monitoring configuration — Dynatrace Docs](https://docs.dynatrace.com/docs/extend-dynatrace/extensions20/data-sources/sql/sap-hana-monitoring)

Query example:

```markup
- subgroup: disk_size_ratio
        query: SELECT D.DATABASE_NAME as DATABASE_NAME, D.HOST as HOST, SUM(T.TABLE_SIZE)/(SELECT TOP 1 ALLOCATION_LIMIT from SYS.M_HOST_RESOURCE_UTILIZATION) as SizeRatio FROM SYS.M_DATABASE D, SYS.M_TABLES T GROUP BY D.DATABASE_NAME, D.HOST;
        dimensions:
          - key: database
            value: col:DATABASE_NAME
          - key: host
            value: col:HOST
        metrics:
          - key: sap.hana.db.disk_size_usage
            value: col:SizeRatio

```

---

<div class="post-metadata">

**Author:** ![david\_lopes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_lopes/32/27273_2.png) [@david\_lopes](https://community.dynatrace.com/u/david_lopes)\
**Post date:** [January 8, 2024, 2:34pm UTC](https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492/3 "2024-01-08T14:34:51Z")

</div>

The issue arises from the use of the **:count** transformation.

Count means “number of datapoints” reported, so you have 3 datapoints reported in that timeframe.  
This is not a useful metric, you should use the actual metric value (with avg, sum, max, etc)

If you strictly need to know the number of rows and doesn’t care about the actual query value, use the metric **custom.db.query.statistics.query.rows** instead.

---

<div class="post-metadata">

**Author:** ![carlos\_carreno](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/carlos_carreno/32/28820_2.png) [@carlos\_carreno](https://community.dynatrace.com/u/carlos_carreno)\
**Post date:** [January 8, 2024, 8:35pm UTC](https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492/4 "2024-01-08T20:35:25Z")

</div>

What I really need to measure is how many records that query retrieves. According to the conditions of the requested query, I wish to be sure that running that query and using the ‘rows’ measure would provide the actual data I need.

When selecting the time period, I want to know exactly how many records there are.

---

<div class="post-metadata">

**Author:** ![david\_lopes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_lopes/32/27273_2.png) [@david\_lopes](https://community.dynatrace.com/u/david_lopes)\
**Post date:** [January 9, 2024, 1:47pm UTC](https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492/5 "2024-01-09T13:47:35Z")

</div>

Yes that is what customers use the extension for regularly

You can use the `COUNT(*)` version of your query, in which case of course it returns a single row, but you can get the query value just fine (do not use the count transformation in the metric selector, like I mentioned)

OR you can have a query that retrieves multiple rows and use the metric I mentioned above.

---

<div class="post-metadata">

**Author:** ![carlos\_carreno](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/carlos_carreno/32/28820_2.png) [@carlos\_carreno](https://community.dynatrace.com/u/carlos_carreno)\
**Post date:** [January 16, 2024, 3:02pm UTC](https://community.dynatrace.com/t/generic-db-query-plugin-sap-hana/43492/6 "2024-01-16T15:02:22Z")

</div>

**Thank you for the options. We’ve decided to go for extension 2.0 to be on the latest extensions right away and be able to adjust our queries there.**
