Page 1 of 1

Batch file with for loop to run SQL SERVER DTS Package

Posted: 12 Apr 2010 01:36
by sauce1979
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

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

Posted: 12 Apr 2010 03:17
by jeb
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

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

Posted: 12 Apr 2010 03:38
by sauce1979
Many thanks, that did the trick. I have spent all weekend trying to solve this and now it works. Much appreciated.