SQL命令模式-无法运行命令

时间:2018-11-28 15:15:52

标签: sql-server sql-server-2012

我只是回答了这个问题,但从未尝试运行它。所以我尝试了 SQL command mode SQL SERVER - unable to Print

我以为如果Print可以正常运行,那么该命令肯定会运行,但是令我惊讶的是

    USE [DBName]  
        :setvar ScriptPath 'C:\Work\'
        :setvar SQLFile 'Test.sql'

         ----- commented  PRINT $(ScriptPath) + $(SQLFile)    ---- Works 
        GO
         :r $(ScriptPath) + $(SQLFile)   ---  Doesn't work 
-- throws:A fatal scripting error occurred. Incorrect syntax was encountered while parsing :r

             :r $(ScriptPath)+$(SQLFile)   ---  Doesn't work 
    -- throws:A fatal scripting error occurred. Unable to process :r command
             GO

我进行了搜索,但找不到正确的答案。

这里需要解决什么?

1 个答案:

答案 0 :(得分:1)

这有效。

USE [DBName]  
        :setvar ScriptPath "C:\Work\"
        :setvar SQLFile "Test.sql"

        GO
         :r $(ScriptPath)$(SQLFile)