Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Does NULL <> 'string'?

Does NULL <> 'string'?

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasehelpquestion
55 Posts 20 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Richard DeemingR Richard Deeming

    0x01AA wrote:

    BTW: Have some Problems to seriously translate "if you're anal about compliance"

    anal - Wiktionary[^] - definition #3: of a person, compulsive and stubborn, obsessed with neatness and accuracy Synonyms: fussy, pernickety, picky


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #46

    Thank you for help me learning English. What such a insignifican word like "about" can change everything :laugh: Thank you Bruno

    1 Reply Last reply
    0
    • C Chris Maunder

      You'd think so. Except in SQL We had a query:

      Select count(*)
      From TableOne

      which returned, say, 500,000 records. Next we added

      Select count(*)
      From TableOne
      Left Join TableTwo On TableTwo.TableTwoID = TableOne.TableTwoID
      Where TableTwo.TableTwoID is null or TableTwo.StringColumn <> 'value'

      We're trying to find the number of records in TableOne which, when joined with TableTwo, either have no corresponding TableTwo row or the corresponding TableTwo row is not 'value'. TableTwo.StringColumn is nullable. The result? Adding the join resulted in 25K records. It should have been over 490K records. The issue?

      TableTwo.StringColumn <> 'value'

      This comparison returns false if TableTwo.StringColumn is null. So one needs to use

      IsNull(TableTwo.StringColumn, '') <> 'value'

      to get the correct result.

      cheers Chris Maunder

      H Offline
      H Offline
      hpcoder2
      wrote on last edited by
      #47

      Actually, the same sort of thing happens in floating point arithmetic, in pretty much any language under the sun. The values NaN (yes, there's more than one type of NaN) always return false when compared with any other number. So both NaN==x and NaN != x are false. etc., etc. This has bitten me in the arse a number of times, and I work in C++.

      1 Reply Last reply
      0
      • C Chris Maunder

        You'd think so. Except in SQL We had a query:

        Select count(*)
        From TableOne

        which returned, say, 500,000 records. Next we added

        Select count(*)
        From TableOne
        Left Join TableTwo On TableTwo.TableTwoID = TableOne.TableTwoID
        Where TableTwo.TableTwoID is null or TableTwo.StringColumn <> 'value'

        We're trying to find the number of records in TableOne which, when joined with TableTwo, either have no corresponding TableTwo row or the corresponding TableTwo row is not 'value'. TableTwo.StringColumn is nullable. The result? Adding the join resulted in 25K records. It should have been over 490K records. The issue?

        TableTwo.StringColumn <> 'value'

        This comparison returns false if TableTwo.StringColumn is null. So one needs to use

        IsNull(TableTwo.StringColumn, '') <> 'value'

        to get the correct result.

        cheers Chris Maunder

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #48

        Chris Maunder wrote:

        to get the correct result.

        The other result was also correct, just not the one you wanted. The behaviour is logical. Your last example would be very VB-ish, where a "NULL" value is treated like an empty string. In the database-world, an empty value does not mean an empty string. ..and it is not something recent, is it? :p

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        C 1 Reply Last reply
        0
        • L Lost User

          Chris Maunder wrote:

          to get the correct result.

          The other result was also correct, just not the one you wanted. The behaviour is logical. Your last example would be very VB-ish, where a "NULL" value is treated like an empty string. In the database-world, an empty value does not mean an empty string. ..and it is not something recent, is it? :p

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

          C Offline
          C Offline
          Chris Maunder
          wrote on last edited by
          #49

          Eddy Vluggen wrote:

          The other result was also correct, just not the one you wanted

          This is exactly why I love programming.

          cheers Chris Maunder

          T 1 Reply Last reply
          0
          • N Nelek

            Guys... this is not the soapbox

            M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

            T Offline
            T Offline
            TheGreatAndPowerfulOz
            wrote on last edited by
            #50

            It's also not the lounge.

            #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

            1 Reply Last reply
            0
            • C Chris Maunder

              Eddy Vluggen wrote:

              The other result was also correct, just not the one you wanted

              This is exactly why I love programming.

              cheers Chris Maunder

              T Offline
              T Offline
              TheGreatAndPowerfulOz
              wrote on last edited by
              #51

              My sarcasm meter just broke.

              #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

              1 Reply Last reply
              0
              • L Lost User

                Yes, and it is pretty correct. NULL is not defined and can therefore not be compared to a value. Also not for nuallable type in c#.

                R Offline
                R Offline
                Rob Grainger
                wrote on last edited by
                #52

                Exactly - in Codd's original work (which defined Relational Database Management Systems), this is referred to as null progagation. Interesting, in The Relational Model for Database Management Systems V2, he introduced two null values one indicates the value is unknown and inapplicable (like the null behaviour you described), and the other indicating the value is unknown and applicable (which would give the behaviour Chris was expecting). Sadly, to the best of my knowledge, no-one bothered pursuing any of the good ideas in there.

                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                1 Reply Last reply
                0
                • C Chris Maunder

                  You'd think so. Except in SQL We had a query:

                  Select count(*)
                  From TableOne

                  which returned, say, 500,000 records. Next we added

                  Select count(*)
                  From TableOne
                  Left Join TableTwo On TableTwo.TableTwoID = TableOne.TableTwoID
                  Where TableTwo.TableTwoID is null or TableTwo.StringColumn <> 'value'

                  We're trying to find the number of records in TableOne which, when joined with TableTwo, either have no corresponding TableTwo row or the corresponding TableTwo row is not 'value'. TableTwo.StringColumn is nullable. The result? Adding the join resulted in 25K records. It should have been over 490K records. The issue?

                  TableTwo.StringColumn <> 'value'

                  This comparison returns false if TableTwo.StringColumn is null. So one needs to use

                  IsNull(TableTwo.StringColumn, '') <> 'value'

                  to get the correct result.

                  cheers Chris Maunder

                  R Offline
                  R Offline
                  Rob Grainger
                  wrote on last edited by
                  #53

                  I prefer the idiom...

                  (TableTwo.StringColumn <> 'value') or TableTwo.StringColumn is null

                  I find it a bit more readable (never really liked the name of the IsNull function).

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                  1 Reply Last reply
                  0
                  • C Chris Maunder

                    You'd think so. Except in SQL We had a query:

                    Select count(*)
                    From TableOne

                    which returned, say, 500,000 records. Next we added

                    Select count(*)
                    From TableOne
                    Left Join TableTwo On TableTwo.TableTwoID = TableOne.TableTwoID
                    Where TableTwo.TableTwoID is null or TableTwo.StringColumn <> 'value'

                    We're trying to find the number of records in TableOne which, when joined with TableTwo, either have no corresponding TableTwo row or the corresponding TableTwo row is not 'value'. TableTwo.StringColumn is nullable. The result? Adding the join resulted in 25K records. It should have been over 490K records. The issue?

                    TableTwo.StringColumn <> 'value'

                    This comparison returns false if TableTwo.StringColumn is null. So one needs to use

                    IsNull(TableTwo.StringColumn, '') <> 'value'

                    to get the correct result.

                    cheers Chris Maunder

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #54

                    In the end I can feel with you. I just entered the trap with NULL values _one more again_ :^) :-D SELECT xyz FROM Tbl1 LEFT JOIN Tbl2 ON Tbl2.Tbl1_ID = Tbl1.ID WHERE Tbl1.IntValue <> Tbl2.IntValue Where in both tables NULL Values are allowed for the field IntValue. S*t happens :doh:

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      You'd think so. Except in SQL We had a query:

                      Select count(*)
                      From TableOne

                      which returned, say, 500,000 records. Next we added

                      Select count(*)
                      From TableOne
                      Left Join TableTwo On TableTwo.TableTwoID = TableOne.TableTwoID
                      Where TableTwo.TableTwoID is null or TableTwo.StringColumn <> 'value'

                      We're trying to find the number of records in TableOne which, when joined with TableTwo, either have no corresponding TableTwo row or the corresponding TableTwo row is not 'value'. TableTwo.StringColumn is nullable. The result? Adding the join resulted in 25K records. It should have been over 490K records. The issue?

                      TableTwo.StringColumn <> 'value'

                      This comparison returns false if TableTwo.StringColumn is null. So one needs to use

                      IsNull(TableTwo.StringColumn, '') <> 'value'

                      to get the correct result.

                      cheers Chris Maunder

                      A Offline
                      A Offline
                      al3c
                      wrote on last edited by
                      #55

                      It's either col equals null meaning a field with no value or you've got an epmty string you can use

                      Select *
                      From Table
                      Where (col is null or col = '')

                      or IsNull method to find epty strngs and null values _______________________________________________________________________________________________ Alec programming[^] expert

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups