views:

149

answers:

2

I am trying to create some script variables in T-SQL as follows:

    /*
    Deployment script for MesProduction_Preloaded_KLM_MesSap
    */

    GO
    SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;

    SET NUMERIC_ROUNDABORT OFF;


    GO
    :setvar DatabaseName "MesProduction_Preloaded_KLM_MesSap"

However, when I run this, I get an error stating 'Incorrect syntax near ':'. What am I doing wrong?

+1  A: 

The :setvar only works in SQL command mode, so you are possibly within normal SQL execution in the management studio and have not swapped to command mode.

Andrew
Just to make clear, it is under the menu: Query->SQLCMD mode
demokritos
A: 

try replacing :setvar DatabaseName "MesProduction_Preloaded_KLM_MesSap"

with:

USE [MesProduction_Preloaded_KLM_MesSap]
GO
KM