• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 18882
  • Last Modified:

MS SQL Insert data into table from excel file

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
0
Mehram
Asked:
Mehram
1 Solution
 
momi_sabagCommented:
hi
you can export the data from excel and save it as tab delimited file
then, in mysql you can use the load data command
http://dev.mysql.com/doc/refman/5.0/en/load-data.html

the link describes the syntax and the file format
0
 
emerkelCommented:
Hi,

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

Eddie
0
 
MrNeticCommented:
Mehram,

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

Best Regards,

Paulo Condeça.
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
PeterMacCommented:
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 ??
0
 
Christopher KileCommented:
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.
0
 
pweegarCommented:
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.
0
 
PeterMacCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now