SQLCMD mode in SSMS
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... » read more