SQLCMD mode is a script execution mode that simulates the sqlcmd.exe environment and therefore accepts some commands that are not part of T-SQL language.

Just enable SQLCMD mode in SSMS (Query menu -> SQLCMD Mode) and the query will run fine. SSMS can also be configured to automatically enable SQLCMD mode in Tools menu -> Options -> Query Execution.

SQLCMD mode in SSMS allows you to use the command line tool within SSMS. Using this feature of the SSMS, you don’t have to connect SQLCMD using the command prompt. It is really very helpful and less distracting when you want to connect with multiple SQL Server instances. You can follow the below steps to enable at session level.

  • Go menu option “Query”
  • Click on the SQLCMD mode

Sources:

https://stackoverflow.com/questions/47268990/how-to-generate-a-clean-sql-script-using-visual-studio-database-project

Last modified: November 25, 2024

Author

Comments

Write a Reply or Comment