1

I'm trying to create the following batch file:

@echo off

set "list=AICourse AIStudent Teacher"
set Server="localhost"
set Username="user"
set Password="()$rDCg3st@0"

    for %%n in (%list%) do (

        Set File=c:\temp\%%n.bcp
        Set Log=c:\temp\%%n.log_exp

        ECHO Begin BCP...: %TIME% 
        ECHO waiting...

        bcp Database.dbo.%%n OUT %File% -o %Log% -S%Server% -U%Username% -P%Password% -c

        ECHO End BCP..: %TIME% 
        ECHO Log in file %Log%

    )  

However, when I try to iterate through the array, only returns the last result. How can I iterate then?

1 Answer 1

2

Add this at the top of your script:

SETLOCAL ENABLEDELAYEDEXPANSION

And, then change all the %Log% instances to !Log! and %File% instances to !File!.

Sign up to request clarification or add additional context in comments.

2 Comments

Adding that the tag %File% needs to be modified to!File! too. thanks.
Oops, I missed that one...added it to the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.