Solved

Inserting a 000000 date value in a field

Posted on 2011-02-22
2
647 Views
Last Modified: 2012-05-11
Hello,

I have an ascii file that i am inserting the records into a MS SQL (2008) table.  The Birthdate field is sometimes a valid date in mmddyy format which I am using Substring to put it into yymmdd format for the field in SQL.  The problem is when the date field in the ascii file is all zeros 000000 (mmddyy) Insert script will not run, I get an error saying "Conversion failed when converting date adn/or tiem from character string."  How can I get the ascii date value of 000000 accepted into the SQL date field?  The field in SQL is a date field and allows nulls?

Thanks,
0
Comment
Question by:JohnJMA
2 Comments
 
LVL 8

Accepted Solution

by:
rushShah earned 500 total points
ID: 34953930
you can use case when like this,

insert into tablename
select case when date='000000' then null else date end as date
from tablename
0
 

Author Closing Comment

by:JohnJMA
ID: 34955385
Thanks, it works great.
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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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