Batch file with for loop to run SQL SERVER DTS Package

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sauce1979
Posts: 2
Joined: 12 Apr 2010 01:14

Batch file with for loop to run SQL SERVER DTS Package

#1 Post by sauce1979 » 12 Apr 2010 01:36

I am currently trying to create a batch file which by looping through a list of files imports them into sql via a dts package using DTSRun Utility. I initially tested the batch run DTSRun utility in the batch for one text file and it ran with no problems.

I then added for loop functionality to the batch file to loop through the list of files and this is where I run into trouble.The syntax is as follows:

Code: Select all

for /f "tokens=1,2,3" %%i in (C:\MyImport\Dirlist.txt)
DO
DTSRun /S "(local)" /N "MultipleFileImport" /G "{81FE4AE5-D2CC-47E6-B78C-9309CF4DDFB9}" /L "C:\Documents and Settings\eseosa\My Documents\dtslog.txt" /A "DatabaseName":"8"="ESSBASETESTDW" /A "FileName":"8"="C:\Documents and Settings\eseosa\My Documents\SQL_PRACTICE\%%i" /A "ServerName":"8"="(local)" /W "0" /E


The batch file now does not run. Any ideas on where I may be going wrong

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Batch file with for loop to run SQL SERVER DTS Package

#2 Post by jeb » 12 Apr 2010 03:17

Hi sauce1979,

first of all your syntax seems to be invalid, because if you want to use the for-loop the "DO" have to be on the same line
and the statement also or the block of statements have to begin on that line.

Code: Select all

set "myGuid={81FE4AE5-D2CC-47E6-B78C-9309CF4DDFB9}"
set "myLog=C:\Documents and Settings\eseosa\My Documents\dtslog.txt"
set "myPath=C:\Documents and Settings\eseosa\My Documents\SQL_PRACTICE"

for /f "tokens=1,2,3" %%i in (C:\MyImport\Dirlist.txt) DO (

DTSRun /S "(local)" /N "MultipleFileImport" /G "%myGuid%" /L "%myLog%" /A "DatabaseName":"8"="ESSBASETESTDW" /A "FileName":"8"="%myPath%\%%i" /A "ServerName":"8"="(local)" /W "0" /E

)



jeb

sauce1979
Posts: 2
Joined: 12 Apr 2010 01:14

Re: Batch file with for loop to run SQL SERVER DTS Package

#3 Post by sauce1979 » 12 Apr 2010 03:38

Many thanks, that did the trick. I have spent all weekend trying to solve this and now it works. Much appreciated.

Post Reply