{"id":444,"date":"2010-07-14T11:20:59","date_gmt":"2010-07-14T10:20:59","guid":{"rendered":"http:\/\/www.aleprex.it\/wordpress\/?p=444"},"modified":"2010-07-14T11:22:01","modified_gmt":"2010-07-14T10:22:01","slug":"sql-tips-ansi_nulls","status":"publish","type":"post","link":"https:\/\/www.aleprex.it\/wordpress\/sql-tips-ansi_nulls.html","title":{"rendered":"SQL Tips : ANSI_NULLS"},"content":{"rendered":"<p><a href=\"http:\/\/www.aleprex.it\/wordpress\/wp-content\/uploads\/2010\/07\/SQLTIPS.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-457 alignnone\" style=\"margin: 3px;\" title=\"SQLTIPS\" src=\"http:\/\/www.aleprex.it\/wordpress\/wp-content\/uploads\/2010\/07\/SQLTIPS.png\" alt=\"\" width=\"170\" height=\"150\" \/><\/a><\/p>\n<p>La seguente query :<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n\r\nSELECT DISTINCT Color from Production.Product\r\nWHERE Color IS NOT NULL;\r\n\r\n<\/pre>\n<p><!--more--><br \/>\ncome sappiamo tutti ritorna la lista dei <strong>Color <\/strong>dalla tabella <strong>Product <\/strong>non considerando i valori che sono a <strong>NULL<\/strong>.<\/p>\n<p><a href=\"http:\/\/www.aleprex.it\/wordpress\/wp-content\/uploads\/2010\/07\/tips011.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-455\" title=\"tips01\" src=\"http:\/\/www.aleprex.it\/wordpress\/wp-content\/uploads\/2010\/07\/tips011.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/www.aleprex.it\/wordpress\/wp-content\/uploads\/2010\/07\/tips011.png 800w, https:\/\/www.aleprex.it\/wordpress\/wp-content\/uploads\/2010\/07\/tips011-300x225.png 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>ma se scriviamo la stessa query utilizzando l&#8217;operatore di confronto<strong> &#8220;diverso da&#8221; (&lt;&gt;)<\/strong> non otteniamo lo stesso risultato!<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT DISTINCT Color from Production.Product\r\nWHERE Color &lt;&gt; NULL;\r\n\r\n<\/pre>\n<p>Questo perch\u00e8 di default Sql Server ha impostato il flag <strong>ANSI_NULLS<\/strong> su <strong>ON <\/strong>e quindi non \u00e8 possibile  equiparare i valori a <strong>NULL <\/strong>e dar\u00e0 come risultato &#8220;<strong><em>unknown<\/em><\/strong>\u201d.<\/p>\n<p>Per poter far si che l&#8217;operatore <strong>&#8220;&lt;&gt;&#8221;<\/strong> venga considerato bisogna settare il flag<strong> ANSI_NULLS OFF<\/strong> in questo modo:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n\r\nUSE AdventureWorks\r\n\r\nGO\r\n\r\nSET ANSI_NULLS OFF;\r\n\r\nSELECT DISTINCT Color from Production.Product\r\nWHERE Color &lt;&gt; NULL;\r\n\r\n<\/pre>\n<p><span style=\"font-size: xx-small;\"><em>riferimento : <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/Book.aspx?ID=13159&amp;locale=en-us\" target=\"_blank\">MCTS_70-433 Training Kit MS SQL Server 2008 Database Development<\/a><\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>La seguente query : SELECT DISTINCT Color from Production.Product WHERE Color IS NOT NULL;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[29,27,3],"tags":[],"class_list":["post-444","post","type-post","status-publish","format-standard","hentry","category-coding","category-programmazione","category-sql"],"_links":{"self":[{"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/posts\/444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/comments?post=444"}],"version-history":[{"count":16,"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/posts\/444\/revisions"}],"predecessor-version":[{"id":463,"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/posts\/444\/revisions\/463"}],"wp:attachment":[{"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/media?parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/categories?post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aleprex.it\/wordpress\/wp-json\/wp\/v2\/tags?post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}