<?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: Null Value Exploration in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833225#M4864068</link>
    <description>&lt;P&gt;@Ron: To add: Note that for CHECK constraints, the logic is different: They are only violated by conditions that evaluate to FALSE. Therefore, something like CHECK(@value = 1) will accept both a value of 1 and the NULL value. So this is different from WHERE clauses.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2010 17:04:46 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2010-12-06T17:04:46Z</dc:date>
    <item>
      <title>Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaq-p/13833216</link>
      <description>&lt;P&gt;I have two statements that seem the same that look for the same rows with the same null values.  One returns the correct results and one returns 0 results.  &lt;/P&gt;

&lt;P&gt;With this table having some null values:&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;CREATE TABLE "AACoupons" (
"AACouponID" INTEGER NOT NULL DEFAULT AUTOINCREMENT,
"CouponAmount" INTEGER NULL,
"AAItemID" INTEGER NULL,
PRIMARY KEY ( "AACouponID" ASC )
) ;

INSERT INTO "AACoupons" ("AACouponID","CouponAmount","AAItemID") VALUES(300,2,3);
INSERT INTO "AACoupons" ("AACouponID","CouponAmount","AAItemID") VALUES(301,4,3);
INSERT INTO "AACoupons" ("AACouponID","CouponAmount","AAItemID") VALUES(302,6,3); 
INSERT INTO "AACoupons" ("AACouponID","CouponAmount","AAItemID") VALUES(500,162,NULL);
INSERT INTO "AACoupons" ("AACouponID","CouponAmount","AAItemID") VALUES(501,NULL,NULL);
INSERT INTO "AACoupons" ("AACouponID","CouponAmount","AAItemID") VALUES(506,NULL,NULL);
&lt;/LI-CODE&gt;

&lt;P&gt;Why is it that this statement returns 3 results:&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;select * from AACoupons where AAItemID = null;
&lt;/LI-CODE&gt;

&lt;P&gt;But this block returns 0 results:&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;begin
declare &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1491879"&gt;@Noval&lt;/a&gt; int;
set &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1491879"&gt;@Noval&lt;/a&gt; = null;
select * from AACoupons where AAItemID = &lt;a href="https://community.sap.com/t5/user/viewprofilepage/user-id/1491879"&gt;@Noval&lt;/a&gt;;
end;
&lt;/LI-CODE&gt;

&lt;P&gt;I realize the variable is an intermediate step, but the variable is null on initializing and then it is explicitly set to null so I do not understand the difference.  &lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2010 19:51:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaq-p/13833216</guid>
      <dc:creator>former_SQLA_member1694868</dc:creator>
      <dc:date>2010-12-03T19:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833217#M4864060</link>
      <description>&lt;P&gt;I haven't tested your code, but the first place I'd look it to see what exactly is in the @noVal variable.&lt;/P&gt;

&lt;P&gt;Null is not a value, it is the absence of a value.  You are probably treading in very dangerous territory here of unpredictable results.&lt;/P&gt;

&lt;P&gt;If it your intent to look for nulls, use IS NULL.   &lt;/P&gt;

&lt;LI-CODE lang="sql"&gt; select * from AACoupons where AAItemID IS NULL;
&lt;/LI-CODE&gt;

&lt;P&gt;Since it is not a value, the concept of equating null to another value doesn't make sense. &lt;/P&gt;

&lt;P&gt;One of the many things I'm grateful for in SQLA is that it allows me to divide by zero to  return a null, rather than crashing and burning on a div by zero error. (It's an option,and not default behavior since when, maybe release 4.something?) &lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2010 20:11:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833217#M4864060</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-12-03T20:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833220#M4864063</link>
      <description>&lt;P&gt;The divide by 0 trick is a good one to know.  I'm not looking for null explicitly.  The variable value is filled in dynamically, but if it is null I would like it to return the corresponding rows that have a null value, but if the value is 3 then return the rows that have a value of 3.&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;I would think having set the variable = null would settle what was in it.&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;I just wondered why.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2010 20:50:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833220#M4864063</guid>
      <dc:creator>former_SQLA_member1694868</dc:creator>
      <dc:date>2010-12-03T20:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833218#M4864061</link>
      <description>&lt;P&gt;I suspect that the &lt;A href="http://dcx.sybase.com/index.html#1200en/dbadmin/ansinull-option.html" rel="nofollow"&gt;ansinull option&lt;/A&gt; is set to ON on your connection when you ran your first statement, and your first statement, by itself without any other information, is treating the "AAItemID = null" as a TSQL comparison and therefore is using TSQL semantics. As such, the test for null will do what you appear to want - that is check for null values - and will return three rows.&lt;/P&gt;

&lt;P&gt;In your second example, the existence of the "begin ... end" block is telling SQL Anywhere that you are using the Watcom SQL dialect and hence is using ANSI semantics. As such the predicate "AAItemID = @NoVal" or even "AAItemID = null" will never match any rows because nothing &lt;EM&gt;equals&lt;/EM&gt; null in ANSI-land.&lt;/P&gt;

&lt;P&gt;Please see &lt;A href="http://dcx.sybase.com/index.html#1200en/dbreference/nulls.html" rel="nofollow"&gt;the NULL value documentation&lt;/A&gt; for more information about the treatment of NULL in SQL Anywhere.&lt;/P&gt;

&lt;P&gt;As Ron has pointed out, if you are wanting to find null values, the correct method is to use "AAItemID IS NULL".&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2010 21:02:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833218#M4864061</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2010-12-03T21:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833221#M4864064</link>
      <description>&lt;P&gt;Your suspicions are correct.  ansinull was set to ON for both but I incorrectly assumed that "= null" would be the same as "is null" and typed them both with = to keep them as similar as possible, assuming that the variable was somehow to blame.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2010 21:51:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833221#M4864064</guid>
      <dc:creator>former_SQLA_member1694868</dc:creator>
      <dc:date>2010-12-03T21:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833222#M4864065</link>
      <description>&lt;P&gt;Mark, correct me if I'm wrong, but "nothing equals null in ANSI-land" also means that NULL doesn't even equal NULL... which means that a predicate of "WHERE NULL = NULL" will return the same result as "WHERE 1 = 2"&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2010 04:58:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833222#M4864065</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-12-04T04:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833223#M4864066</link>
      <description>&lt;P&gt;@Ron: IMHO, that's not completely true: 1=2 returns FALSE whereas NULL = NULL returns UNKNOWN. However, in a WHERE clause, only conditions evaluating to TRUE are returned, so in your example, both comparisons are not TRUE, and as such, they are filtered out.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2010 10:47:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833223#M4864066</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-12-04T10:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833219#M4864062</link>
      <description>&lt;P&gt;If you want to have a comparison that returns TRUE in both cases:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;not-null-value = the-same-not-null-value&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;and &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;null = null&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;and you're using SA12, you can use the new (and ANSI-compliant) &lt;A href="http://dcx.sybase.com/index.html#1200en/dbreference/is-distinct-from-search-condition.html" rel="nofollow"&gt;&lt;STRONG&gt;NOT DISTINCT FROM&lt;/STRONG&gt; search condition&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;I.e.&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;col1 not distinct from col2
&lt;/LI-CODE&gt;

&lt;P&gt;is sematically the same as&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;col1 = col2 or (col1 is null and col2 is null)
&lt;/LI-CODE&gt;

&lt;P&gt;However, the performance for NOT DISTINCT FROM should be better, as it is &lt;EM&gt;sargable&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2010 10:57:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833219#M4864062</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-12-04T10:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833224#M4864067</link>
      <description>&lt;P&gt;Another new one that is good to know.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2010 01:21:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833224#M4864067</guid>
      <dc:creator>former_SQLA_member1694868</dc:creator>
      <dc:date>2010-12-05T01:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Null Value Exploration</title>
      <link>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833225#M4864068</link>
      <description>&lt;P&gt;@Ron: To add: Note that for CHECK constraints, the logic is different: They are only violated by conditions that evaluate to FALSE. Therefore, something like CHECK(@value = 1) will accept both a value of 1 and the NULL value. So this is different from WHERE clauses.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2010 17:04:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/null-value-exploration/qaa-p/13833225#M4864068</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-12-06T17:04:46Z</dc:date>
    </item>
  </channel>
</rss>

