Solved

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

Posted on 2009-07-16
6
1,125 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now