I am working with some SQL-scripts that I want to be reusable, så I need to use some variables.
I have a bat script that run the sql script with sqlcmd
sqlcmd -S <SERVER> -v PROJECT="<PROJECTNAME>" -i .\start.sql
I did a little experiment, as I know I've managed to get a syntax similar to this to work for me before now. I found that if I replicated what you had done, I got the following error:
A fatal scripting error occurred. Cannot find directory in the path specified for ":r" command.
If instead, I put the whole of the path into the variable - it works. So try changing your .sql file to this:
and calling it from SQLCMD like this:
sqlcmd -S <SERVER> -v PROJECT_FILE_NAME=".\<PROJECTNAME>\init.sql" -i .\start.sql
When I took this approach, it ran the file
init.sql with no errors.