Solved

Importing CSV File into the SQL Server

Posted on 2014-01-08
5
1,390 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

Zoho SalesIQ

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Minus first query 1 36
SQL 2008 Conversion failed 7 20
Generate Weekly Schedule 15 17
MS SQL Server - Looking to filter rows based on column value 3 9
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
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…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

896 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

15 Experts available now in Live!

Get 1:1 Help Now