Setting Null value in SQL update statement

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
R

Robert Dufour

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,Optional Byval FK as integer = ? )
Any help would be greatly appreciated
Thanks
Bob
 
Robert said:
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,Optional 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
 
Thanks
Bob
Jester98x said:
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
 
Back
Top