0

I have the following files in my folder:

Script1.sql
Script2.sql
Script3.sql

The below command executes each script successfully:

@echo off

set /p sname= Please enter the servername:
set /p dbname= Please enter the databasename:

ECHO started the batch process at %TIME%  >output.txt

for %%f in (*.sql) do (
sqlcmd.exe  -S %sname% -d %dbname% -i %%f  >>output.txt

%~f0"

    )
pause

Results are

(1 rows affected)

(3 rows affected)

(2 rows affected)

What I would like to know is how can i input the file name after each file is executed and this name stored in the output.txt file ie

(1 rows affected)

Script1.sql

(3 rows affected)

Script2.sql

(2 rows affected)

Script3.sql

Any help appreciated

1 Answer 1

4

Just output the file name, what's problem?

for %%f in (*.sql) do (
   echo %%~nf >> output.txt
   sqlcmd.exe  -S %sname% -d %dbname% -i %%f  >>output.txt
)
Sign up to request clarification or add additional context in comments.

3 Comments

This only prints the file name in the command line, I need to print it in the output.txt file
No, Im stuck on this one. Any help will be appreciated.
Try it now. It was missing a closing parenthesis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.