我需要下一个:当变量recode(x, a = "apple", b = "banana", .default = NA_character_)
[1] "apple" "banana" "apple" "banana" "banana" "apple" NA NA NA "apple"
不为null时,请使用“ @SCOPE
”,否则请忽略此过滤器。
第一个sql:
like
当范围为null时第二个
DECLARE @SCOPE varchar = '%test%'
select id, scope from delivery
where scope like @SCOPE
类似这样的东西:
DECLARE @SCOPE varchar = NULL
select id, scope from deliver
但这不是正确的SQL查询。范围为空时,我不需要使用“ DECLARE @SCOPE varchar = null
select id, scope from delivery
where
scope like
(CASE
WHEN @SCOPE IS NULL THEN scope ELSE @SCOPE
END)
”。
我该怎么做?
答案 0 :(得分:3)
只需使用not_analyzed
:
or
答案 1 :(得分:0)
做同一件事的另一种方式。
select * from delivery where ISNULL(scope,'') like ISNULL(@scope, ISNULL(scope,''))