Null Value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joel

    #1

    Null Value


    Hi,

    I added a field to my company table (PBV_rstCompany .Fields("Instal ler")) the
    default value of the field is Null. I place this If statement and it doesn't
    work

    If PBV_rstCompany. Fields("Install er") <> "Y" Then
    txtInstaller.Vi sible = False
    lblInstallerLBL .Visible = False
    cmdNextInstalle r.Visible = False
    cmdPrevInstalle r.Visible = False
    End If

    It assumes the statement is false when in fact it's true... Null in not
    equal "Y"!



  • Gordon Burditt

    #2
    Re: Null Value

    >I added a field to my company table (PBV_rstCompany .Fields("Instal ler")) the[color=blue]
    >default value of the field is Null. I place this If statement and it doesn't
    >work
    >
    > If PBV_rstCompany. Fields("Install er") <> "Y" Then
    > txtInstaller.Vi sible = False
    > lblInstallerLBL .Visible = False
    > cmdNextInstalle r.Visible = False
    > cmdPrevInstalle r.Visible = False
    > End If
    >
    >It assumes the statement is false when in fact it's true... Null in not
    >equal "Y"![/color]

    Get used to SQL 3-valued logic. The result of:

    PBV_rstCompany. Fields("Install er") <> "Y"
    when the left side is null has the value null, not false or true.
    Similarly,
    x = null
    is never true, it's null. The correct test is
    x is null

    You probably want to write your test:
    [color=blue]
    > If PBV_rstCompany. Fields("Install er") <> "Y"[/color]
    or PBV_rstCompany. Fields("INstall er") is null
    Then

    Gordon L. Burditt

    Comment

    • Bill Karwin

      #3
      Re: Null Value

      Joel wrote:[color=blue]
      > I added a field to my company table (PBV_rstCompany .Fields("Instal ler")) the
      > default value of the field is Null. I place this If statement and it doesn't
      > work[/color]

      Almost any expression involving a NULL yields a NULL as the value of the
      expression. A NULL expression in a boolean condition such as your IF
      works like FALSE for purposes of satisfying the condition.

      In SQL, NULL is a state, not a value. You cannot compare NULL to
      anything -- it will always yield NULL. The idea is that NULL represents
      the absence of a value, or an unknown value, or a value that has not
      been set yet. E.g., is my middle name "Kevin"? We cannot say for
      sure--no value has been entered in the middle_name field yet.

      If you must have a non-null state in your "Installer" field, then you
      should delare it as a NOT NULL field in your schema, and perhaps also
      give it a DEFAULT value. This is appropriate if you have a field that
      _must_ be either "Y" or "N", and using NULL to indicate an absence of a
      value is meaningless for that field.

      Otherwise you must handle the case of a NULL state differently than
      handling value comparisons. SQL provides a predicate IS [NOT] NULL,
      which returns true or false.

      Regards,
      Bill K.

      Comment

      Working...