Results 1 to 5 of 5

Thread: Null and ""

  1. #1
    Join Date
    Sep 2005
    Posts
    313

    Unanswered: Null and ""

    Hi:

    I have a question
    In VB Code:

    case 1: I set one variable to be Null
    value1 = Null

    OR

    case 2: I set one variable to be ""
    value1 = ""

    What is the difference?
    Is the "" still count one character??? "" => 1 character
    Null is meaning nothing, empty, right.
    If (isnull(value1)) then
    ...
    end if

    From above code, case1 will be worked, right.

    Please let me know, thanks.

    Thanks.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    I think that the example of a variable (or table field) containing a zero length string and a variable as null can be thought of as a bit like two transparent boxes - one contains air, the other a vacuum. From the outside they look the same but climb inside whilst confusing the two and you are in a world of trouble.

    The length (try the Len or LenB functions) of "" = 0.

    Null actually can be thought of as Unknown. "" is effectively nothing (in so far as a box contianing air contains nothing - it does contain something just not anything people would usually consider remarking upon) - however the crucial thing is that you know that the value is nothing. Null is simply unknown - there might be a value, just that no one knows it or it hasn't been entered into the database yet. Of course - it could be that the true value is nothing - you just don't know. Try typing:

    ?1 = Null

    into the immediate winidow and press return. The answer is Null - not false as you might expect - i.e. Unknown

    Any clearer?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by pootle flump
    I think that the example of a variable (or table field) containing a zero length string and a variable as null can be thought of as a bit like two transparent boxes - one contains air, the other a vacuum. From the outside they look the same but climb inside whilst confusing the two and you are in a world of trouble.
    this gots to be quote of the week

    what a gorgeous analogy

    nice job

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by r937
    this gots to be quote of the week

    what a gorgeous analogy

    nice job

    Thanks Rudy I've been waiting for a post to try it out on.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Feb 2004
    Location
    Irving, TX (Dallas, Fort Worth)
    Posts
    379

    You got it Right!

    Quote Originally Posted by accessman2
    Is the "" still count one character??? "" => 1 character
    Null is meaning nothing, empty, right.
    Yup your right. If you need to test for both it is:
    Code:
     If isnull(value1) OR value1 = "" then
        ...
     endif
    DBS4M

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •