0

I want to conditionally run a post-deploy script. My script (currently) looks like this:

declare @tier nvarchar(100) = $(tier)
if( @tier = 'TEST' )
    begin
    :r .\ConfigSeedData.TEST.sql
    end

I have defined the variable in the project file, as detailed in Using variable in sql postdeployment build script?. The variable is (currently) defined as TEST (no quotes, but I've tried it with quotes, too).

However, no matter how I try to twist my syntax, I keep getting this error: .Net SqlClient Data Provider: Msg 207, Level 16, State 1, Line 875 Invalid column name 'TEST'.

How do I check a sqlcmd variable for a literal value, not a column?

I have tried adding the square brackets around the $(), tried accessing the value directly (without assigning to nvarchar).

Thanks!!

4

1 回答 1

0

事实证明,您需要在变量 use 周围加上单引号。为了使上述工作,代码将是:

if( '$(tier)' = 'TEST' )

因此,即使看起来您使用的是文字“ $(tier)”,但实际上它是从引号中拉出、解释并放回的。

于 2019-02-08T20:23:42.220 回答