Profiling and debugging "Incorrect syntax was encountered while parsing :setvar." I have the following script using SQLCMD setvar, but I receive an error when I parse the script:

:setvar dbname "PROD"
:setvar backuppath = "e:\sql\restore\PROD.bak"

USE [master];
GO

-- backup the existing PRODUCTION database
BACKUP DATABASE [$(dbname)]
TO DISK = '$(backuppath)'
WITH COPY_ONLY, COMPRESSION

-- we need to clear the existing PRODCOPY users
-- before we restore and replace
IF DB_ID('PRODCOPY') IS NOT NULL
BEGIN
    -- Remove any connected users
    ALTER DATABASE [PRODCOPY]
    SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    WAITFOR DELAY '00:00:05'
    ALTER DATABASE [PRODCOPY]
    SET MULTI_USER
END

-- restore PROD as PRODCOPY
-- ...


The error is:

A fatal scripting error occurred.
Incorrect syntax was encountered while parsing :setvar.


If I comment out the section:

IF DB_ID('PRODCOPY') IS NOT NULL
BEGIN
...
END


Then the error goes away. It seems like the use of SQLCMD is actually testing whether the PRODCOPY database exists, which of in this case it doesn't.

I've tried to use profiler, but although I can see the SQL commands:

SET PARSEONLY ON
SET PARSEONLY OFF


However, profiler is not logging anything in between the two instructions that should be parsed, but I still see the error! Any ideas what I need to do to see the content that is supposed to be parsed by the server? Which columns, events to trace?

Is this an oddity with SQLCMDs?
:setvar backuppath = "e:\sql\restore\PROD.bak"


should be

:setvar backuppath "e:\sql\restore\PROD.bak"