I'm having a problem specifying a value within an OPTIMIZE FOR statement. I'd like to optimize the query with the value as a string, but I must be doing something wrong, because SQL gives the following error:
在 OPTIMIZE FOR 子句中为变量“@test”指定的值无法隐式转换为该变量的类型。
下面的示例有点人为,但问题与我在实际查询中遇到的问题相同。
declare @TEMP table(asWord nvarchar(max), asNumber int)
insert into @TEMP (asWord, asNumber) values (
'one',
1
), (
'two',
2
)
DECLARE @test nvarchar(max)
SET @test = 'one'
select * from @TEMP
where asWord = @test
OPTION (OPTIMIZE FOR(@test …Run Code Online (Sandbox Code Playgroud)