Solved

Importing Date information from Exel into SQL Server 2008 Table

Posted on 2010-11-22
6
388 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
ID: 34187473
How many records?  What is the error?
0
 
LVL 6

Expert Comment

by:subhashpunia
ID: 34187809
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
ID: 34189808
try "set dateformat" on the SQL server, according to the format on the Excel Sheet
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:cipriano555
ID: 34189834
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
ID: 34195549
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
ID: 34198686
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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