?
Solved

Importing CSV File into the SQL Server

Posted on 2014-01-08
5
Medium Priority
?
1,442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 1600 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 13

Assisted Solution

by:Koen Van Wielink
Koen Van Wielink earned 200 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:Ramesh Babu Vavilla
Ramesh Babu Vavilla earned 200 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 13

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

743 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