Yua*_*rto 11 sql arrays where sql-server-2008
+------------------+
| id1 | id2 | bool |
+------------------+
| 1 | 1 | F |
| 1 | 2 | F |
| 2 | 1 | F |
+------------------+
UPDATE table_name
SET bool = T
WHERE (id1, id2) IN ((1,1),(2,1)) --Need work here
Run Code Online (Sandbox Code Playgroud)
所以基本上我想选择(id1,id2)=(value1,value2)的条件.与以下声明类似:
WHERE id1 = value1 AND id2 = value2
Run Code Online (Sandbox Code Playgroud)
但是在数组中的值集合中.这可能吗?
提前致谢
编辑:我正在使用SQL Server 2008.如果不太清楚,我很抱歉.我正在尝试将其作为存储过程并从服务中调用它.输入将是某种数组(可变大小),并找到与行中的两个ID匹配.
这是在 MSSql 中执行此操作的方法。您所需要的只是从 Id1 和 Id2 生成一个值(在本示例中为 VARCHAR)。在这种情况下,您可以使用 IN 语句来设置值。另外,您还应该考虑 id1 和 id2 中的 NULL(如果这些字段中允许使用 NULL and id1 is not null and id2 is not null
)(只需添加:)。
UPDATE table_name
SET bool = T
WHERE convert(varchar(20),id1)+','+convert(varchar(20),id2) in ('1,1','2,1')
Run Code Online (Sandbox Code Playgroud)