Solved

multiple text file import into MSSQL

Posted on 2007-03-22
2
1,321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
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 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…

739 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