Setting Null value in SQL update statement

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

    #1

    Setting Null value in SQL update statement

    I have a sub to update a record in a sql server 2000 table.
    There's a field FK, which is defined to allow nulls in the table definition,
    the field type is integer.
    How do I write the sub's definition where the parameter FK is of type
    integer but it's value can be NULL?


    UpdateDB(ByVal ID as Integer,Optiona l Byval FK as integer = ? )
    Any help would be greatly appreciated
    Thanks
    Bob


  • Jester98x

    #2
    Re: Setting Null value in SQL update statement

    Robert Dufour wrote:
    I have a sub to update a record in a sql server 2000 table.
    There's a field FK, which is defined to allow nulls in the table definition,
    the field type is integer.
    How do I write the sub's definition where the parameter FK is of type
    integer but it's value can be NULL?
    >
    >
    UpdateDB(ByVal ID as Integer,Optiona l Byval FK as integer = ? )
    Any help would be greatly appreciated
    Thanks
    Bob
    Hey Bob,

    You don't mention which mechanism you are using to update/insert your
    data. One way would be to set the default value of FK to some number
    you would never expect, eg. -9999, then if FK has this value exclude it
    from the insert. As the field allows NULLs you don't need to supply a
    value for it.

    I don't use Null values too often but I think you could also use
    DBNull.Value, but you'll have to check on that.

    Steve

    Comment

    • Robert Dufour

      #3
      Re: Setting Null value in SQL update statement

      Thanks
      Bob
      "Jester98x" <stephen.wood@w dr.co.ukwrote in message
      news:1161561462 .935386.247710@ k70g2000cwa.goo glegroups.com.. .
      Robert Dufour wrote:
      >I have a sub to update a record in a sql server 2000 table.
      >There's a field FK, which is defined to allow nulls in the table
      >definition,
      >the field type is integer.
      >How do I write the sub's definition where the parameter FK is of type
      >integer but it's value can be NULL?
      >>
      >>
      >UpdateDB(ByV al ID as Integer,Optiona l Byval FK as integer = ? )
      >Any help would be greatly appreciated
      >Thanks
      >Bob
      >
      Hey Bob,
      >
      You don't mention which mechanism you are using to update/insert your
      data. One way would be to set the default value of FK to some number
      you would never expect, eg. -9999, then if FK has this value exclude it
      from the insert. As the field allows NULLs you don't need to supply a
      value for it.
      >
      I don't use Null values too often but I think you could also use
      DBNull.Value, but you'll have to check on that.
      >
      Steve
      >

      Comment

      Working...