MS SQL Insert data into table from excel file

Posted on 2006-11-16
Medium Priority
Last Modified: 2012-05-05
Sir, I have an excel file with the following two columns:

File_job & ICNumber

I have an table in my SQL Server name cargodetail where i have the same column:

file_job & ICNumber

I want to insert data from excel file in my table (cargodetail where file_job table file_job)

Please help
Question by:Mehram
LVL 37

Accepted Solution

momi_sabag earned 1000 total points
ID: 17955750
you can export the data from excel and save it as tab delimited file
then, in mysql you can use the load data command

the link describes the syntax and the file format

Expert Comment

ID: 17955960

Is this a one time import or something that will have to be run periodically?  If it's a one time deal and you have a good text editor, the thing that I have found easier than anything else is just to export the data from excel into a delimited file, as momi sabag said above, then run a regular expression find and replace to generate all the insert lines, then open the file in query analyzer or ssms and run it.  You could also just make a forumla in your excel file to create a column of the insert statements, like 'insert tablename ' + CELL:ROW + ', ' + CELL:ROW and then copy all of the values from that column into query analyzer or ssms and run it.  Either way works really easily.  

Hope this helps


Expert Comment

ID: 17956187

The best practice is to use the SQL Server Import, with this tool, you can directly import the data.

Best Regards,

Paulo Condeça.
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.


Expert Comment

ID: 17957873
Need a little more detail before can give best advice.
Does your SQL Table contain more than just the two already given columns ??
Is this a one off operation, or something you would need to do on a regular basis ??
Are you using full version of MSSQL Server, or cut down version MSDE, or Express ??
Does Excel data contain any leading Zeroes - e.g. File_Job = 000123 ??
LVL 23

Expert Comment

by:Christopher Kile
ID: 17958601
Consult T-SQL help on the stored procedure sp_addlinkedserver, as this includes an Excel example, if you need to use the Excel data directly in queries (and if you have the necessary OLE DB drivers).  Otherwise, some of these other suggestions might prove more useful.

Expert Comment

ID: 17959247
Importing from Excel into SQL Server isn't all that difficult. Open the Entrise manager. Expand Databases and find your db. Right click, then choose "All Tasks". From there choose Import Data. Follow the on line prompts. MAke sure you choose your version of Excel as the source. And choose which db and table to import. Once you have choosen everything, let it run either immediately or whenever you want it to.

Expert Comment

ID: 17963725
Warning, while quite simple in principle, there are number of potential pitfalls with import into SQL. Make sure you have backup of original database, and preferably work initially with copy, until you are sure of what you are doing.
Still need additional information requested before to advise on best method for this.

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

850 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