Solved

Importing CSV File into the SQL Server

Posted on 2014-01-08
5
1,385 Views
Last Modified: 2014-01-09
I want to import the CSV file into the database using the file I uploaded!  The two columns of the data I wanted will be starting from Cell A12 to B12 and down to A27 and B27.  The top portion of the CSV file will be ignore.  I was wondering if anyone done something similar to this?CF20.csvI want to import the CSV file into the database using the file I uploaded!  The two columns of the data I wanted will be starting from Cell A12 to B12 and down to A27 and B27.  The top portion of the CSV file will be ignore.  I was wondering if anyone done something similar to this?
0
Comment
Question by:eli411
5 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 400 total points
ID: 39766993
You can open the file with Excel and remove the information that is not required. I recommend you first delete the rows after 27, and then rows before 12. Also, delete columns after column B. Your csv file will then look like this:
Sanitised dataThen save the file as csv and just use bcp utility to import the file, like this:
bcp MyDatabase.dbo.MayTable in -i c:\temp\cf20.csv -t ","

Open in new window

0
 
LVL 12

Assisted Solution

by:Koen Van Wielink
Koen Van Wielink earned 50 total points
ID: 39767305
Chaau is correct about cleaning up the CSV before importing.
After that, you can alternatively also use the import wizard in the SQL management studio to import the file. Right click on the database name, then select Tasks - Import data. Indicate your data source (flat file for CSV or, if you want to make it a bit simpler, save the csv file as an Excel workbook and select Microsoft Excel as data source). Check the other settings and verify if anything needs changing. On the next screen, indicate your data destination.
When you get to "Select source tables and views" you can have the wizard create a table for you (default), or select an existing table. Always check the mapping if you import into an existing table. After that click next until you can execute the package, and the data should be imported.
0
 
LVL 10

Assisted Solution

by:sqlservr
sqlservr earned 50 total points
ID: 39767374
check this other optino of importing
http://blog.sqlauthority.com/2012/06/20/sql-server-importing-csv-file-into-database-sql-in-sixty-seconds-018-video/

Open in new window

http://blog.sqlauthority.com/2012/06/20/sql-server-importing-csv-file-into-database-sql-in-sixty-seconds-018-video/
0
 
LVL 2

Author Comment

by:eli411
ID: 39768767
Thanks guys!  I was trying to find a way to import the data so some of those administrative people do not have to clean up the CSV file.  I guess that's the only option they got then!
0
 
LVL 12

Expert Comment

by:Koen Van Wielink
ID: 39769772
Where do these csv files originate from? Are they exports from another system? If so, perhaps you can change the way the csv is generated.
Alternatively you might be able to do something with macros/VBA in Excel, where a bit of code would first insert the csv content in a structured Excel template before you import it to SQL. Not my area of expertise but others on this forum know.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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, …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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