我有以下代码,它返回 false 以"@B LIKE @A"
在最后一个语句中进行比较。
我想知道为什么 Like 会以这种方式表现,因为据我所知 Like 是基于文本而不是基于数据类型的比较。
DECLARE @Var1 Char(20)
DECLARE @Var2 VarChar(20)
SET @Var1 = 'X'
SET @Var2 = 'X'
SELECT
@Var1 AS A,
@Var2 AS B,
LEN(@Var1) AS 'A Length',
LEN(@Var2) AS 'B Length',
CASE WHEN @Var1 = @Var2 THEN 'Yes' ELSE 'No' END AS 'A = B',
CASE WHEN @Var1 LIKE @Var2 THEN 'Yes' ELSE 'No' END AS 'A LIKE B',
CASE WHEN @Var2 LIKE @Var1 THEN 'Yes' ELSE 'No' END AS 'B LIKE A'