Setting Null value in SQL update statement

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
 
J

Jester98x

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
 
R

Robert Dufour

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top