Tuesday, August 25, 2009

Data Import from MS Excel to SQL Server 2000/2005

Today I was puzzled to see unexpected results when I tried to do a relatively simple task. I had a excel file and I wanted to import the data from this file into a table in SQL Server 2000/2005. The excel file consisted of many columns of various data types a.k.a intermixed data types. When I imported the file into SQL Server and checked the table, I was surprised to see NULL values for some columnswhen the data acutally existed for those columns in the original excel file. After little bit investigation I learned that the data driver during this taks looks only at the first 8 rows of the data for any column to decide its data type. For some of my columns the first 8 rows had NULL values and when I did the import all the column values were resulted in NULLS even though when the original file had some non-NULL values.

Then I made all the columns on my excel sheet as text using format cells option(to eliminate the intermixed data types issue) but that did not work. I still got the NULL values for some columns.

Finally I got it working when I first imported the data into MS Access db and then imported the MS Access table into SQL Server. I also learned that using flat files instead of excel files would also solve the problem.

The seemingly simple task wasn't actually simple ;). Everyday there is something new to learn.

0 comments:

Post a Comment

About This Blog

In this blog you will find simple but great ideas on various topics ranging from food recipes to investment strategies. I hope the ideas presented in this blog will help you all in some way or other. Also included are the recent and hot news around the world...

Go ahead and grasp my ideas...

Disclaimer and Terms of Use

All the ideas and opinions provided herein are intended to share and inform simple and useful information. They come with no warranty of any kind. If you should choose to interpret graspmyideas.blogspot.com information as perfect working ideas, or advice or if you want to completely rely on these ideas, you do so at your own risk.

This site is offered as is and without warranties of any kind. We are not responsible for timeliness, accuracy, unavailability or interruptions in availability, viruses or other defects in the site or its contents. In no event shall graspmyideas.blogspot.com site or its authors are responsible for any damages to users or their computer systems.


Your Ad Here

  © Blogger template AutumnFall by Ourblogtemplates.com 2008

Back to TOP