Solved

Importing Date information from Exel into SQL Server 2008 Table

Posted on 2010-11-22
6
387 Views
Last Modified: 2012-05-10
I have a table with a definition like this:
CREATE TABLE [dbo].[SPECIAL_DAYS](
      [start_date] [date] NULL,
      [end_date] [date] NULL
) ON [PRIMARY]

I want to populate this table with data from an excel spreadsheet.   I know how to use the SQL Server import and export wizard.  My problem is with data type conversions.  I have tried formatting the spreadsheet as text and as date, but there is always a conversion error and no data gets loaded.    I'm using Excel 2007, and I'd like to do this using the import and export wizard.  How?
0
Comment
Question by:cipriano555
6 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
Comment Utility
How many records?  What is the error?
0
 
LVL 6

Expert Comment

by:subhashpunia
Comment Utility
Try first importing the data in a varchar column as text data. Then add another column in table and update with right conversion functions.
Pls show the data as in excel file and the expected format.
0
 
LVL 18

Expert Comment

by:x-men
Comment Utility
try "set dateformat" on the SQL server, according to the format on the Excel Sheet
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:cipriano555
Comment Utility
subhashpunia.

From your comment you seem to be saying, SQL server import wizard doesn't understand Excel formatting, at least not in this instance.  I would have thought if you formatted your data in Excel as a DATE, the import wizard would say, "oh, this is a date value, it's going into a date field" and do the obvious.  But it doesn't, it converts the date to an integer and then throws a conversion error.

I'm trying to make something easy for a user to input a fairly modest set of time frames, If I have to read it in as a varchar then convert, no problem, but I thought there would be a way to accomplish this directly without doing a conversion as you have described.

John

0
 
LVL 6

Accepted Solution

by:
subhashpunia earned 500 total points
Comment Utility
Yes, Import wizard at least can directly import data in a Date type column. But I here suggested to import data in varchar type columns because sometime due to formatting in excel (some extra character added automatically) do not convert into date type. But after importing in SQL server we have full visibility on data and we can convert as needed.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
Comment Utility
User inputted data is the hardest thing to import because of human error and personal preference.  You don't know if 11/10/2010 is Nov-10 or Oct-11.  Or at least SQL Server doesn't always.  I would recommend, if you are having them input data into Excel, to do the validation into a known format in Excel so that SQL Server doesn't have any issues.  

The most important thing is for the data to be consistent.  Meaning you can't have 12/31/2010 and 31/12/2010 the same column.  Both are valid dates to SQL Server but it can't choose.

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

11 Experts available now in Live!

Get 1:1 Help Now