Solved

multiple text file import into MSSQL

Posted on 2007-03-22
2
1,309 Views
Last Modified: 2008-06-08
I have multiple TAB delimited text files (first row has field names) that I need to import to MSSQL... I don't want to do them one by one.
How can I do multiple file import?
0
Comment
Question by:hbojorquezgeek
2 Comments
 
LVL 16

Expert Comment

by:AdamRobinson
Comment Utility
Perhaps use Perl or PHP to automatically script them?   Read the directory, save the file names in an array, loop through the array performing the mysql connections and the inline import.

0
 

Accepted Solution

by:
magicmike earned 500 total points
Comment Utility
I do a shell command to view all files in a directory and insert into a temp table.
something like this
  DECLARE  @query VARCHAR(1000)
  CREATE TABLE #x (
    Name VARCHAR(200))

  SET @query = 'master.dbo.xp_cmdshell "dir c:\files\*.csv /b"'
 
  INSERT #x
  EXEC( @query)

I run through and insert all into a temp table using OPENROWSET
 SET @Query = 'INSERT into #temptable select * from OPENROWSET(''MSDASQL'', ''Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=' + @Filepath + ';'', ''select * from ' + @Filename + ''') Rowset_1'

after i do that, I take the data, change whats needed then insert into the necessary table.

Sorry I do not have a cleaned up script for you, but i just stumbled on your question online and seen it had no answer.  I hope it works out for you.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I wanted to share this with fellow Experts, who might not know. How often have you wanted to learn something, only to be set back by either restrictions imposed on "trial" or "evaluation" software?  How often have you had to rebuild a home networ…
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

772 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

11 Experts available now in Live!

Get 1:1 Help Now