What about using complete paths, but creating file Main.sql dynamically?
Batch file which expects the 4 script files in folder of the batch file and creates there also Main.sql.
@echo off
set "BatchFolder=%~dp0"
( echo :r %BatchFolder%script1.sql
echo :r %BatchFolder%script2.sql
echo :r %BatchFolder%script3.sql
echo :r %BatchFolder%script4.sql
)>"%BatchFolder%Main.sql"
sqlcmd.exe -E -d "YourDatabaseName" -i "%BatchFolder%Main.sql"
set "BatchFolder="
pause
Open a command prompt window and run there call /?. The help of this command is output in the window explaining %~dp0 which means drive and path of argument 0 ending with a backslash without surrounding quotes. Argument 0 on running of a batch file is the name of the batch file.
Running in command prompt window set /? results in getting help of command set displayed, listing on last help page some special environment variables defined dynamic on running a batch file. The first one listed is %CD% which means current directory.
So instead of working with folder of batch file, it is also possible to work with current folder on batch execution.
@echo off
set "CurrentFolder=%CD%\"
( echo :r %CurrentFolder%script1.sql
echo :r %CurrentFolder%script2.sql
echo :r %CurrentFolder%script3.sql
echo :r %CurrentFolder%script4.sql
)>"%CurrentFolder%Main.sql"
sqlcmd.exe -E -d "YourDatabaseName" -i "%CurrentFolder%Main.sql"
set "CurrentFolder="
pause
The folder path referenced by %CD% does not end with a backslash like the folder path returned by %~dp0 which is the reason for backslash after %CD% on second line.