Solved

Inserting a 000000 date value in a field

Posted on 2011-02-22
2
656 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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