Jimbo99999
asked on
VB.Net - SQL Query to Update Field to Null
Good Day Experts!
Another first in my coding career. In my VB.net program, I need to update a SQL table field to Null. However, in my query I am not sure how to specify to set the field to Null.
How to I set to Null?
Update Customers set TimeEntered = NULL ?
Thanks,
jimbo99999
Another first in my coding career. In my VB.net program, I need to update a SQL table field to Null. However, in my query I am not sure how to specify to set the field to Null.
How to I set to Null?
Update Customers set TimeEntered = NULL ?
Thanks,
jimbo99999
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Either:
Update Customers set TimeEntered = NULL
Or:
Update Customers set TimeEntered = ""
Depending on where you are writing it to.
Double quotes is a blank field and will be seen as a NULL.
Update Customers set TimeEntered = NULL
Or:
Update Customers set TimeEntered = ""
Depending on where you are writing it to.
Double quotes is a blank field and will be seen as a NULL.
@Sodea63: Null and blank are two different values.
update yourtable
set yourcolumn = nullif(yourcolumn,yourcolu mn)
where yourcolumn is not null
set yourcolumn = nullif(yourcolumn,yourcolu
where yourcolumn is not null
If you insert NULL ., you need to handle NULL while fetching also in vb.net code
if Not isdbnull(reader.item("Crea teDate") then
//Your code here
End if
if Not isdbnull(reader.item("Crea
//Your code here
End if
ASKER
Thanks,
jimbo99999
jimbo99999
In T-SQL this is correct for all rows.
If you only wish to do this for a subset of rows, you'll have to add a WHERE clause at the end.
like..
Update Customers set TimeEntered = NULL WHERE id = SomeNumber