<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Query returning NULL - Please help with this in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834791#M4865634</link>
    <description>&lt;P&gt;You need to modify where the Coalesce is used.  It looks like you've combined the embedded select in your set clause from the original; I will assume that's valid.  It is certainly simpler to look at.  Modifying the latest version I see:&lt;/P&gt;
&lt;P&gt;SET t1.kolicina_c=(SELECT &lt;STRONG&gt;COALESCE(&lt;/STRONG&gt;SUM(t2.product_pri)&lt;STRONG&gt;,0)&lt;/STRONG&gt; -&lt;STRONG&gt;COALESCE(&lt;/STRONG&gt;SUM(t2.product_rac)&lt;STRONG&gt;,0)&lt;/STRONG&gt; FROM aos_products_quotes AS t2 WHERE t2.product_id=t1.id_c AND t2.deleted=0 AND pro_usluga_c='proizvod' GROUP BY t2.product_id);&lt;/P&gt;</description>
    <pubDate>Thu, 09 Aug 2012 14:01:26 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2012-08-09T14:01:26Z</dc:date>
    <item>
      <title>Query returning NULL - Please help with this</title>
      <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaq-p/13834786</link>
      <description>&lt;P&gt;DELIMITER $$&lt;/P&gt;
&lt;P&gt;DROP PROCEDURE IF EXISTS &lt;CODE&gt;lunasoft&lt;/CODE&gt;.&lt;CODE&gt;kalkulacija&lt;/CODE&gt;$$&lt;/P&gt;
&lt;P&gt;CREATE DEFINER=&lt;CODE&gt;root&lt;/CODE&gt;@&lt;CODE&gt;localhost&lt;/CODE&gt; PROCEDURE &lt;CODE&gt;kalkulacija&lt;/CODE&gt;()&lt;/P&gt;
&lt;P&gt;BEGIN&lt;/P&gt;
&lt;P&gt;update aos_products_cstm as t1&lt;/P&gt;
&lt;P&gt;set t1.kolicina_c=(select sum(t2.product_pri) from aos_products_quotes as t2 where t2.product_id=t1.id_c and t2.deleted=0 and pro_usluga_c='proizvod' group by t2.product_id) - (select sum(t2.product_rac) from aos_products_quotes as t2 where t2.product_id=t1.id_c and t2.deleted=0 and pro_usluga_c='proizvod' group by t2.product_id);&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="k"&gt;END&lt;/SPAN&gt;&lt;SPAN class="vg"&gt;$$&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;DELIMITER ;&lt;/P&gt;
&lt;P&gt;DELIMITER $$&lt;/P&gt;
&lt;P&gt;DROP TRIGGER /&lt;EM&gt;!50032 IF EXISTS &lt;/EM&gt;/ &lt;CODE&gt;lunasoft&lt;/CODE&gt;.&lt;CODE&gt;racun_unos&lt;/CODE&gt;$$&lt;/P&gt;
&lt;P&gt;CREATE
    /&lt;EM&gt;!50017 DEFINER = 'root'@'localhost' &lt;/EM&gt;/
    TRIGGER &lt;CODE&gt;racun_unos&lt;/CODE&gt; AFTER INSERT ON &lt;CODE&gt;aos_products_quotes&lt;/CODE&gt; 
    FOR EACH ROW BEGIN 
call kalkulacija;
END;
$$&lt;/P&gt;
&lt;P&gt;DELIMITER ;&lt;/P&gt;
&lt;P&gt;DELIMITER $$&lt;/P&gt;
&lt;P&gt;DROP TRIGGER /&lt;EM&gt;!50032 IF EXISTS &lt;/EM&gt;/ &lt;CODE&gt;lunasoft&lt;/CODE&gt;.&lt;CODE&gt;racun_izmjena&lt;/CODE&gt;$$&lt;/P&gt;
&lt;P&gt;CREATE
    /&lt;EM&gt;!50017 DEFINER = 'root'@'localhost' &lt;/EM&gt;/
    TRIGGER &lt;CODE&gt;racun_izmjena&lt;/CODE&gt; AFTER UPDATE ON &lt;CODE&gt;aos_products_quotes&lt;/CODE&gt; 
    FOR EACH ROW BEGIN 
call kalkulacija;
END;
$$&lt;/P&gt;
&lt;P&gt;DELIMITER ;&lt;/P&gt;
&lt;P&gt;DELIMITER $$&lt;/P&gt;
&lt;P&gt;DROP TRIGGER /&lt;EM&gt;!50032 IF EXISTS &lt;/EM&gt;/ &lt;CODE&gt;lunasoft&lt;/CODE&gt;.&lt;CODE&gt;racun_brisanje&lt;/CODE&gt;$$&lt;/P&gt;
&lt;P&gt;CREATE
    /&lt;EM&gt;!50017 DEFINER = 'root'@'localhost' &lt;/EM&gt;/
    TRIGGER &lt;CODE&gt;racun_brisanje&lt;/CODE&gt; AFTER DELETE ON &lt;CODE&gt;aos_products_quotes&lt;/CODE&gt; 
    FOR EACH ROW BEGIN 
call kalkulacija;
END;
$$&lt;/P&gt;
&lt;P&gt;DELIMITER ;&lt;/P&gt;
&lt;P&gt;Please help with this kolicina_c only be shown if both fields are filled and product_pri product_rac. I would like to make kolicina_c displayed if only one field filled. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2012 17:42:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaq-p/13834786</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-07T17:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Query returning NULL - Please help with this</title>
      <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834787#M4865630</link>
      <description>&lt;P&gt;If I understand correctly, if either expression in your update statement above are null you get a null result.&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;Depending on the semantics of a null in your system, you may want the Coalesce function.  It looks like you are summing some values, so it may be reasonable to assume a null value is equivalent to zero.  On the other hand, if there are no values in any of the rows that create the sum (or associated rows from the table you are summing) you have missing data, and using 0 may be misleading.  You will have to decide.&lt;/P&gt;
&lt;P&gt;So your first expression in the update may be:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;COALESCE&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="nb"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sum&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;t2&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;product_pri&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;from&lt;/SPAN&gt; &lt;SPAN class="n"&gt;aos_products_quotes&lt;/SPAN&gt; &lt;SPAN class="n"&gt;as&lt;/SPAN&gt; &lt;SPAN class="n"&gt;t2&lt;/SPAN&gt; &lt;SPAN class="n"&gt;where&lt;/SPAN&gt; &lt;SPAN class="n"&gt;t2&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;product_id&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="n"&gt;t1&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;id_c&lt;/SPAN&gt; &lt;SPAN class="ow"&gt;and&lt;/SPAN&gt; &lt;SPAN class="n"&gt;t2&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;deleted&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;0&lt;/SPAN&gt; &lt;SPAN class="ow"&gt;and&lt;/SPAN&gt; &lt;SPAN class="n"&gt;pro_usluga_c&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'proizvod'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;group&lt;/SPAN&gt; &lt;SPAN class="n"&gt;by&lt;/SPAN&gt; &lt;SPAN class="n"&gt;t2&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;product_id&lt;/SPAN&gt;&lt;SPAN class="p"&gt;),&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;0&lt;/SPAN&gt; &lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 07 Aug 2012 20:20:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834787#M4865630</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-07T20:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Query returning NULL - Please help with this</title>
      <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834788#M4865631</link>
      <description>&lt;P&gt;Ron thanks a lot for your response. This is my formula for a warehouse, where the field kolicina_c stock of a product. Product_pri field is related to the receipt, and field product_rac is related to the invoice. An example of a product beer does not have stocks, until you make invoice and receipt. Condition for the product to be displayed when only one document is created.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2012 03:49:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834788#M4865631</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-08T03:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Query returning NULL - Please help with this</title>
      <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834789#M4865632</link>
      <description>&lt;P&gt;It work just making the point that SUM() ignores individual rows that have null values, but if all the rows are null or if there are no rows then SUM() will return a null. If, as in your example, you then try to  use that value in an operation with other non-null values, you will always get an overall null - ie NULL + x = NULL&lt;/P&gt;
&lt;P&gt;see &lt;A href="http://dcx.sybase.com/index.html#1001/en/dbrfen10/rf-sum.html"&gt;http://dcx.sybase.com/index.html#1001/en/dbrfen10/rf-sum.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and &lt;A href="http://dcx.sybase.com/index.html#1001/en/dbrfen10/rf-nulls.html"&gt;http://dcx.sybase.com/index.html#1001/en/dbrfen10/rf-nulls.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2012 07:02:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834789#M4865632</guid>
      <dc:creator>justin_willey</dc:creator>
      <dc:date>2012-08-08T07:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Query returning NULL - Please help with this</title>
      <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834790#M4865633</link>
      <description>&lt;P&gt;Sounds like 0 is the answer you want in case of nulls then.  Justin did a better job of explaining &lt;STRONG&gt;why&lt;/STRONG&gt; you are getting a null, but the Coalesce function should take care of the symptoms.&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;For docs see &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/coalesce-function.html"&gt;http://dcx.sybase.com/index.html#1201/en/dbreference/coalesce-function.html&lt;/A&gt; 
That's for SA 12.0.1 but it's been basically the same for as many major versions as I can recall.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2012 11:29:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834790#M4865633</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-08T11:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Query returning NULL - Please help with this</title>
      <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834791#M4865634</link>
      <description>&lt;P&gt;You need to modify where the Coalesce is used.  It looks like you've combined the embedded select in your set clause from the original; I will assume that's valid.  It is certainly simpler to look at.  Modifying the latest version I see:&lt;/P&gt;
&lt;P&gt;SET t1.kolicina_c=(SELECT &lt;STRONG&gt;COALESCE(&lt;/STRONG&gt;SUM(t2.product_pri)&lt;STRONG&gt;,0)&lt;/STRONG&gt; -&lt;STRONG&gt;COALESCE(&lt;/STRONG&gt;SUM(t2.product_rac)&lt;STRONG&gt;,0)&lt;/STRONG&gt; FROM aos_products_quotes AS t2 WHERE t2.product_id=t1.id_c AND t2.deleted=0 AND pro_usluga_c='proizvod' GROUP BY t2.product_id);&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2012 14:01:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834791#M4865634</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-08-09T14:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Query returning NULL - Please help with this</title>
      <link>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834792#M4865635</link>
      <description>&lt;P&gt;Is this a question about MySQL?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Aug 2012 08:38:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/query-returning-null-please-help-with-this/qaa-p/13834792#M4865635</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2012-08-12T08:38:20Z</dc:date>
    </item>
  </channel>
</rss>

