I would like a stored procedure to import data from a .txt or .xls file to a database using SQL Server. I will...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
use temporary tables to copy from the file and then I'll transfer from the temporary tables to the database. Could you please give me an example of such a procedure?
There are many ways to import data into SQL Server and what you choose depends greatly on your specific scenario. If you want to simply load contents of a text file into a temporary table, the BULK INSERT command should do the trick. If the number and the order of the columns in the file is the same as in the destination table, your statement could be as simple as this:
BULK INSERT MyTable
FIELDTERMINATOR =' |',
ROWTERMINATOR =' |\n'
If you want to exclude some columns or modify the order of columns, create a format file and specify it as a parameter to BULK INSERT. You can refer to books online to learn more about how to use BULK INSERT and how to create a format file.
Dig Deeper on SQL Server Stored Procedures
Related Q&A from Roman Rehak
There are a few things you can do to tune SQL Server for improved reporting performance. Here are some generic and Reporting Services-specific ...continue reading
Is a license needed for a standby server if it's used for SQL Server replication? Get that answer and a comparison of SQL Server log shipping to ...continue reading
Learn about working with image files in SQL Server, including advice on using queries to locate them, in this expert answer.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.