Solved

multiple text file import into MSSQL

Posted on 2007-03-22
2
1,325 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…
Suggested Courses

635 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