Home All Groups Group Topic Archive Search About

Setting Null value in SQL update statement

Author
22 Oct 2006 3:12 PM
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

Author
22 Oct 2006 11:57 PM
Jester98x
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,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
Author
23 Oct 2006 2:58 PM
Robert Dufour
Thanks
Bob
Show quoteHide quote
"Jester98x" <stephen.w***@wdr.co.uk> wrote in message
news:1161561462.935386.247710@k70g2000cwa.googlegroups.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(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
>