VB.Net - SQL Query to Update Field to Null

Posted on 2013-02-06
Last Modified: 2013-02-07
Good Day Experts!

Another first in my coding career.  In my 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 ?

Question by:Jimbo99999
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 75

Accepted Solution

Aneesh Retnakaran earned 200 total points
ID: 38861736
thats right

Update Customers set TimeEntered = NULL
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 50 total points
ID: 38861737
Assuming your column allows nulls to start with, yes, that is exactly how you would do it :)
LVL 65

Expert Comment

by:Jim Horn
ID: 38861738
>Update Customers set TimeEntered = NULL ?
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.


Update Customers set TimeEntered = NULL WHERE id = SomeNumber
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.


Expert Comment

ID: 38861739
Update Customers set TimeEntered = NULL
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.
LVL 39

Expert Comment

ID: 38861936
@Sodea63: Null and blank are two different values.
LVL 50

Expert Comment

ID: 38861999
update yourtable
  set yourcolumn = nullif(yourcolumn,yourcolumn)
 where yourcolumn is not null
LVL 10

Expert Comment

by:Monica P
ID: 38863136
If you insert NULL ., you need to handle NULL while fetching also in code

if Not isdbnull(reader.item("CreateDate") then
//Your code here
End if

Author Closing Comment

ID: 38863978

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question