<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">on MSSQL (tried on 2012) the GetxxxDCIValue works only with integer values, not with floating points (the wiki states numeric type).</p>
<p dir="auto">I tried to simulate "manually" the query using this statement (reported in this thread <a href="https://www.netxms.org/forum/configuration/getavgdcivalue-not-working/msg11517/#msg11517" rel="nofollow ugc">https://www.netxms.org/forum/configuration/getavgdcivalue-not-working/msg11517/#msg11517</a><img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61e.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--disappointed" style="height:1.4em;width:auto;vertical-align:middle" title="):" alt="😞" /></p>
<p dir="auto">SELECT avg(coalesce(idata_value,0)) FROM idata_&lt;node_id&gt; WHERE item_id=&lt;dci_id&gt; and idata_timestamp between &lt;time_from&gt; and &lt;time_to&gt;</p>
<p dir="auto">but with floating point values I get the following error message:</p>
<p dir="auto">Conversion failed when converting the varchar value '14.2999710' to data type int</p>
<p dir="auto">Is this a restriction that applies only on MSSQL?</p>
<p dir="auto">Best regards,<br />
Marco</p>
]]></description><link>https://forum.netxms.org/topic/3109/getxxxdcivalue-avg-max-min-fails-on-floating-point-numbers</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 23:10:40 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/3109.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Apr 2014 16:03:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers on Fri, 25 Apr 2014 09:04:06 GMT]]></title><description><![CDATA[<p dir="auto">Same for Oracle DB:</p>
<pre><code>select avg(TO_NUMBER(idata_value,'99999.999999')) from IDATA_100 where ITEM_ID = '7'
</code></pre>
<p dir="auto">Возможно надо будет увеличить маску (добавить пару-тройку девяток перед точкой).</p>
]]></description><link>https://forum.netxms.org/post/13730</link><guid isPermaLink="true">https://forum.netxms.org/post/13730</guid><dc:creator><![CDATA[andrey--k]]></dc:creator><pubDate>Fri, 25 Apr 2014 09:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers on Fri, 25 Apr 2014 07:20:52 GMT]]></title><description><![CDATA[<p dir="auto">I've added fix for MS SQL as suggested.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/13729</link><guid isPermaLink="true">https://forum.netxms.org/post/13729</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Fri, 25 Apr 2014 07:20:52 GMT</pubDate></item><item><title><![CDATA[Reply to GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers on Thu, 24 Apr 2014 21:33:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/andrey-k" aria-label="Profile: andrey-k">@<bdi>andrey-k</bdi></a> said in <a href="/post/13720">GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers</a>:</p>
<blockquote>
<p dir="auto">Can you try next example:</p>
<pre><code>SELECT avg(coalesce(to_number(idata_value),0)) FROM idata_&lt;node_id&gt; WHERE item_id=&lt;dci_id&gt; and idata_timestamp between &lt;time_from&gt; and &lt;time_to&gt;
</code></pre>
</blockquote>
<p dir="auto">Hi!,</p>
<p dir="auto">to_number isn't present in MSSQL, it can be substituted with CAST (as per Victor's suggestion), to have it working on int and float it could be casted always to float as in this example:</p>
<pre><code>SELECT avg(coalesce(cast(idata_value as float),0)) FROM idata_&lt;node_id&gt; WHERE item_id=&lt;dci_id&gt; and idata_timestamp between &lt;time_from&gt; and &lt;time_to&gt;
</code></pre>
<p dir="auto">I would like to suggest also a check for numeric in the where condition (and isnumeric(idata_value)=1), running the above query on my DB I've discovered some dirty unvalid values in my records that caused failing of the query.</p>
<p dir="auto">The final query should be something like:</p>
<pre><code>SELECT avg(coalesce(cast(idata_value as float),0)) FROM idata_&lt;node_id&gt; WHERE item_id=&lt;dci_id&gt; and isnumeric(idata_value)=1 and idata_timestamp between &lt;time_from&gt; and &lt;time_to&gt;
</code></pre>
<p dir="auto">Is there a little hope to have a GetSumDCIValue implemented in the meanwhile you add this fix?  <img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61b.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--stuck_out_tongue" style="height:1.4em;width:auto;vertical-align:middle" title=":P" alt="😛" /></p>
<p dir="auto">Best regards,<br />
Marco</p>
]]></description><link>https://forum.netxms.org/post/13724</link><guid isPermaLink="true">https://forum.netxms.org/post/13724</guid><dc:creator><![CDATA[Jmp_3f8h]]></dc:creator><pubDate>Thu, 24 Apr 2014 21:33:22 GMT</pubDate></item><item><title><![CDATA[Reply to GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers on Thu, 24 Apr 2014 17:57:06 GMT]]></title><description><![CDATA[<p dir="auto">Can you try next example:</p>
<pre><code>SELECT avg(coalesce(to_number(idata_value),0)) FROM idata_&lt;node_id&gt; WHERE item_id=&lt;dci_id&gt; and idata_timestamp between &lt;time_from&gt; and &lt;time_to&gt;
</code></pre>
]]></description><link>https://forum.netxms.org/post/13720</link><guid isPermaLink="true">https://forum.netxms.org/post/13720</guid><dc:creator><![CDATA[andrey--k]]></dc:creator><pubDate>Thu, 24 Apr 2014 17:57:06 GMT</pubDate></item><item><title><![CDATA[Reply to GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers on Thu, 24 Apr 2014 16:25:53 GMT]]></title><description><![CDATA[<p dir="auto">Hi!</p>
<p dir="auto">Seems to be implicit data conversion issue. Can you try modify this query somehow to make it work (maybe cast idata_value to numeric type)? If you will make it wor, I'll fix server code to handle it correctly <img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/13717</link><guid isPermaLink="true">https://forum.netxms.org/post/13717</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Thu, 24 Apr 2014 16:25:53 GMT</pubDate></item><item><title><![CDATA[Reply to GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers on Tue, 22 Apr 2014 18:24:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/andrey-k" aria-label="Profile: andrey-k">@<bdi>andrey-k</bdi></a> said in <a href="/post/13682">GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers</a>:</p>
<blockquote>
<p dir="auto">to take math functions you should convert data from varchar to digits.<br />
I use transit table in separate shema for this purpose.</p>
</blockquote>
<p dir="auto">Hi andrey--k,</p>
<p dir="auto">Maybe I didn't understand your reply but my concern was related to the original GetxxxDCIValue, I'm not interested in running the query "manually". I ran the query as per suggestion in the reported thread just as a "proof" for the result. So, I was interested in knowing if the GetAvgDCIValue (for example) fails on floating point numbers only using MSSQL as backend DB or if this is a behaviour common even to the other DB engines supported by NetXMS.</p>
<p dir="auto">Best regards,<br />
Marco</p>
]]></description><link>https://forum.netxms.org/post/13683</link><guid isPermaLink="true">https://forum.netxms.org/post/13683</guid><dc:creator><![CDATA[Jmp_3f8h]]></dc:creator><pubDate>Tue, 22 Apr 2014 18:24:19 GMT</pubDate></item><item><title><![CDATA[Reply to GetxxxDCIValue (Avg/Max/Min) fails on floating point numbers on Tue, 22 Apr 2014 18:08:25 GMT]]></title><description><![CDATA[<p dir="auto">to take math functions you should convert data from varchar to digits.<br />
I use transit table in separate shema for this purpose.</p>
]]></description><link>https://forum.netxms.org/post/13682</link><guid isPermaLink="true">https://forum.netxms.org/post/13682</guid><dc:creator><![CDATA[andrey--k]]></dc:creator><pubDate>Tue, 22 Apr 2014 18:08:25 GMT</pubDate></item></channel></rss>