【发布时间】:2015-02-20 13:08:17
【问题描述】:
我有两个用于开发的环境,我希望能够从另一个脚本中运行其他脚本。目前,当我需要在两个环境之间切换时,我必须手动注释掉我不需要的路径:
--:SETVAR scriptPath "D:\Scripts\Mark\Documents\Data Integrations\"
:SETVAR scriptPath "C:\Users\Mark\Documents\Data Integrations\"
:r $(scriptPath)"General Scripts"\"Functions and Setup".sql
这段代码运行良好,但我想做的是添加一个分支语句来自动选择正确的路径。
:SETVAR ServerName "(CAST(SERVERPROPERTY('MachineName') AS NVARCHAR(100)))"
DECLARE @Path NVARCHAR(MAX)
IF $(ServerName) = 'Computer1'
SELECT @Path = 'C:\Users\Mark\Documents\Data Integrations\'
ELSE
SELECT @Path = 'D:\Scripts\Mark\Documents\Data Integrations\'
:SETVAR scriptPath @Path
:r $(scriptPath)"General Scripts"\"Functions and Setup".sql
但使用此代码时,我收到“发生致命脚本错误。 在为 ":r" 命令指定的路径中找不到目录。错误。
我做错了什么?
【问题讨论】:
-
尝试使用不带空格的目录名进行测试。我认为一些带有空格符号的目录名称不是双引号。因此,请彻底检查您的脚本,以确保空间不会破坏任何路径。
标签: sql-server-2008 tsql sqlcmd