add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE t (c1 int, c2 int, c3 int, c4 int, c5 int)
INSERT INTO t (c1, c2, c3, c4, c5) VALUES
(10, 1, 2, 3, 4),
(20, 5, 6, 7, 8),
(30, 9, 10, 11, 12),
(40, 13, 14, 15, 16)
4 rows affected
select *
, sk = row_number() over (order by c1)
, k1 = row_number() over (order by newid())
, k2 = row_number() over (order by newid())
, k3 = row_number() over (order by newid())
into #temp
from t
4 rows affected
select *
from #temp
order by c1
c1 c2 c3 c4 c5 sk k1 k2 k3
10 1 2 3 4 1 1 4 3
20 5 6 7 8 2 2 1 4
30 9 10 11 12 3 4 2 1
40 13 14 15 16 4 3 3 2
update t set
t.c2 = a.c2,
t.c3 = b.c3,
t.c4 = c.c4,
t.c5 = c.c5
from t
join #temp as x on t.c1 = x.c1
join #temp as a on x.sk = a.k1
join #temp as b on x.sk = b.k2
join #temp as c on x.sk = c.k3
4 rows affected
select *
from t
order by c1
c1 c2 c3 c4 c5
10 1 6 11 12
20 5 10 15 16
30 13 14 3 4
40 9 2 7 8