views:

701

answers:

3

I am using SQL Server Management Studio to run a script on SQL Server 2008. Following simple statement throws error "Incorrect syntax near ':'".

:setvar DatabaseName "USHR1.2"

Curious, what's going on here. Appreciate your help!

+5  A: 

use TSQL....

DECLARE @databaseName VARCHAR(7)
SET @databaseName = 'USHR1.2'
StingyJack
VARCHAR(7) -- :)
abatishchev
A: 

Or use ' instead of "

abatishchev
+1  A: 

OK.. it was simple. Enabling the "SQLCMD Mode" from the SSMS menu solved the error. Thanks everyone for your replies.

I guess, there are tons of such "Incorrect syntax near 'x'" errors reported on stackoverflow. Guess, those will go away with this fix.

pencilslate

related questions