根据变量返回不以数字结尾的值

Returning values not ending in digits based upon variable

我正在将一个变量传递到我的存储过程中,并在我的 WHERE 子句中编写一个 case 语句。通常我会这样写:

CodeID like CASE WHEN @Duration != '0' 
                THEN '%' + @Duration 
                ELSE '%' END

然而,问题是这不是我所需要的。我真正需要的是 IF @Duration != '0' THEN CodeID like '%' + @Duration ELSE CodeID 不以数字结尾的东西。

这可能吗?我考虑过写几个 IF 语句,每个语句都有各自的查询,但由于没有数字通配符,我在处理这个逻辑时也遇到了一些麻烦。

怎么样:

(@Duration <> '0' and codeid like '%' + @duration) or
(@Duration = '0' and codeid like '%[0-9]')
   

What I actually need is something with the logic of IF @Duration != '0' THEN CodeID like '%' + @Duration ELSE CodeID doesn't end with a digit.

使用布尔逻辑:

where 
    (@duration <> '0' and CodeID like '%' + @Duration)
    or (@duration = '0' and CodeID not like '%[0-9]')