Solved

multiple text file import into MSSQL

Posted on 2007-03-22
2
1,318 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
ID: 18786169
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
ID: 20023095
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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…

830 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