Solved

Copy only dates

Posted on 2016-09-18
3
69 Views
Last Modified: 2016-09-18
I am trying to make NULL fields that are not dates, date should only be either:

mm/dd/yyyy  OR mm/dd/yy

Anything that is not that format should be made NULL

Here is my current sql

UPDATE  dbo.Dependents SET DepLastUSEntry = NULL 
WHERE ISDATE(DepLastUSEntry)= 0

Open in new window


It is not making some of the fields NULL not sure why.  Perhaps it is allowing some 'dates' that are not in the format above, is there a way to check that it IS in the format as listed above ?
0
Comment
Question by:amucinobluedot
  • 2
3 Comments
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
Comment Utility
Here you go

--

UPDATE  dbo.Dependents SET DepLastUSEntry = NULL 
WHERE ISDATE(FORMAT(DepLastUSEntry,'mm/dd/yyyy'))= 0

--

Open in new window


Pls let me know if you face any issues
0
 
LVL 17

Accepted Solution

by:
Pawan Kumar Khowal earned 500 total points
Comment Utility
If above dont work then you write 2 statements

--

UPDATE  dbo.Dependents SET DepLastUSEntry = NULL 
WHERE ISDATE(FORMAT(DepLastUSEntry,'mm/dd/yyyy'))= 0


UPDATE  dbo.Dependents SET DepLastUSEntry = NULL 
WHERE ISDATE(FORMAT(DepLastUSEntry,'mm/dd/yy'))= 0

--

Open in new window

0
 

Author Closing Comment

by:amucinobluedot
Comment Utility
Thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
The viewer will learn how to count occurrences of each item in an array.

771 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

12 Experts available now in Live!

Get 1:1 Help Now