Search code examples
sql-serversql-server-2012sqlcmd

Getting an Error "The file specified for :r command was not found"


I have the following code which I'm trying to run from the SSMS SQL Cmd Mode

:setvar SQLScriptPath "D:\DBScript\"

:r  $(SQLScriptPath)\001_CreateTables_User.SQL;

:r  $(SQLScriptPath)\002_CreateTables_SystemSettings.sql;

But while executing this, I'm getting the below error

A fatal scripting error occurred. The file specified for :r command was not found.

I tried with and without both single and double quotes, but no Luck. Any Help is much appreciated.

Thanks in Advance


Solution

  • Remove the semi-colon for the :r commands. Semi-colon is used to terminate a SQL command. :r is a tool "command", processed by sqlcmd.exe/SSMS.