SQL update where in set of data SQL update where in set of data arrays arrays

SQL update where in set of data


Here is the way to do it in MSSql. All you need is to make one value (in this example VARCHAR) from Id1 and Id2. In this case you can use IN statement with the values set. Also you should think about NULLs in id1 and id2 if they are allowed in these fields (just add: and id1 is not null and id2 is not null).

UPDATE table_nameSET bool = TWHERE convert(varchar(20),id1)+','+convert(varchar(20),id2) in ('1,1','2,1')


One idea to achieve this is make use of temp table

Create Table #Temp(  id1 int,  id2 int)insert into #Temp values(1,1)insert into #Temp values(1,2)insert into #Temp values(2,1)insert into #Temp values(2,2)--update dataUPDATE table_name SET bool = T from table_name T1   inner join #Temp T2 on T1.Id1= T2.Id1and T1.Id2= T2.Id2


Try This - SQL Server 2008 Version.

create table mytable(id1 int,id2 int,bool char(1));insert INTO mytable VALUES(1,1,'F');insert INTO mytable VALUES(1,2,'F');insert INTO mytable VALUES(2,1,'F');SELECT * FROM mytable;update mytable set bool='T'WHERE exists (SELECT id1,id2 from mytable tb2where mytable.id1 = 1 AND mytable.id2 = 1or mytable.id1 = 2 AND mytable.id2 = 1);SELECT * from mytable;