-1

我正在尝试检查某个列是否具有以下内容:

SELECT Id,
CASE CHARINDEX(Name,'Value A') WHEN 0 THEN '0'
      ELSE '1'
END
FROM TABLE

这适用于测试Value A;现在我想检查多个值。例如,我想检查是否Name匹配任何Value A, Value B, Value CCHARINDEX一次只允许一个。

有办法做到这一点吗?

4

1 回答 1

1
SELECT id, 
    iif (Name LIKE '%Value A%' OR Name LIKE '%Value B%', 1, 0) AS IsContainsTheValue
  FROM Table;

这假设值是静态的,这似乎是您的问题的情况。

编辑精确匹配

Declare @matchValues Table (Value varchar(100));
-- maybe you could pass a table from the application??

SELECT id, 
    iif (v.Value Is Not Null, 1, 0) AS IsContainsTheValue
  FROM Table AS t
  LEFT JOIN @matchValues AS v On t.Name = v.Value;
于 2016-11-15T10:42:23.020 回答