SQL Server ':setvar' Error

后端 未结 4 1901
逝去的感伤
逝去的感伤 2020-12-12 13:15

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

    /*
    Deployment script for MesProduction_Preloaded_KLM_MesSap
    */

    GO
    SET A         


        
相关标签:
4条回答
  • 2020-12-12 13:43

    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.

    This can be done through the user interface in SQL Server Management Studio by going to the "Query" menu, and selecting "SQLCMD mode."

    0 讨论(0)
  • 2020-12-12 13:50

    FOR SQL2012:

    go to : tools/options/Query Execution and check the by default, open new queries in SQLCMD mode.

    Hit the New Query button and make sure the variable definitions are highlighted, your script should run correctly now.

    Previous versions:

    http://blog.sqlauthority.com/2013/06/28/sql-server-how-to-set-variable-and-use-variable-in-sqlcmd-mode/

    0 讨论(0)
  • 2020-12-12 13:52

    Just enable sqlcmd mode in SQL Server Management Studio as described in following image.

    0 讨论(0)
  • 2020-12-12 13:58

    try replacing :setvar DatabaseName "MesProduction_Preloaded_KLM_MesSap"

    with:

    USE [MesProduction_Preloaded_KLM_MesSap]
    GO
    
    0 讨论(0)
提交回复
热议问题