Solved

How to convert blank datetime field to NULL again?  SQL 2008 backend of VB Windows App

Posted on 2009-07-16
6
1,131 Views
Last Modified: 2013-11-26
I have a windows application written in VB from Visual Studio.  SQL 2008 Backend.  For datetime fields, if the user removes the date after they have entered one, it does not remove the date..... I understand it wants a valid date, but how can I delete a date that was entered by mistake?  Returning the field to NULL.
0
Comment
Question by:sassymacke
6 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24871270
This should update it back to NULL:

UPDATE ur_table
SET datetime_col_name = NULL
WHERE pk = pk_value
0
 
LVL 13

Expert Comment

by:Surone1
ID: 24871276
update table set fieldname = NULL
0
 

Author Comment

by:sassymacke
ID: 24871615
I'm sorry... I should have clarified a bit better.

I want the program to change the field value to NULL if it is empty, anytime it's empty.  Possibly this does it, I'm not sure how I'd use it....

I use the tableadapters in Visual Studio.  Is there a way to insert code on save event that checks for "" and then changes to NULL?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 9

Expert Comment

by:Ernariash
ID: 24872562

I think you answer yourself to insert code on save event that checks for "" and then changes to NUL&
Or if you are using Store procedure. ( I am assuming you field is Nullable)
you can check for you string and converted there.

if (@yourdatetimeParam = ) set @yourdatetimeParam = null
//This one will check for any non datetime including empty strings
if (IsDate(@yourdatetimeParam)=0) set @yourdatetimeParam = null
 
0
 

Author Comment

by:sassymacke
ID: 24872695
I'm not using a stored procedure.  What code would I insert on save event?  I've tried to get something to work but had no luck.
0
 
LVL 9

Accepted Solution

by:
Ernariash earned 500 total points
ID: 24874242

You can try inline T-SQL to accomplish the same...hope this help you...
if your parameter is not a date then insert or update with nulls
 CASE WHEN IsDate(@yourdatetimeParam)=0 THEN NULL ELSE @yourdatetimeParam END
UPDATE ur_table
SET datetime_col_name = CASE WHEN IsDate(@yourdatetimeParam)=0 THEN NULL ELSE @yourdatetimeParam END
WHERE ....

0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
query optimization 6 21
Need return values from a stored procedure 8 40
Groupbox Control ? 2 27
how to loop through and process two columns in excel 8 46
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

679 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