Solved

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

Posted on 2009-07-16
6
1,133 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
[X]
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
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

734 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