Solved

Importing Date information from Exel into SQL Server 2008 Table

Posted on 2010-11-22
6
389 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dimension table indexes 8 25
kill process lock Sql server 9 46
Challenging SQL Update 5 41
SQL Server 2012 r2 - Calulations within stored procedure involving temp tables 6 28
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…
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…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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